<?php
/*
// 生成模块： writeMainMenuItemFile（写入主菜单项文件） writeIndexPages writeProPageIndex（写入产品页和产品详细页文件）
// 写入模块： writelog writeconstant writegeneralfile（写入一般文件） 
// 获取模块： getproductfolder
// 图片函数：  addWatermark ImageResize   getimagewh   ifanimationgif

------------------------------------------------------
参数：
$path	路径

程序功能：夹函数
------------------------------------------------------
*/
	function createFolder($path){
		if (!file_exists($path)){		//假如文件夹不存在
			createFolder(dirname($path));	//取得最后一个文件夹的全路径返回开始的地方
	//		$path=iconv("UTF-8","GB2312","$path");
			mkdir($path, 0775);
		}
	}

	/*
------------------------------------------------------
参数：
$path	路径

程序功能：清理文件夹字符串函数并同时将多余空格删除
------------------------------------------------------
*/
function clearFolder($path)
{
	//$clearstr=array("/","\\","'","\"",",",":",">","<","&","*","(",")","@","#","+","-","=","$","!","|",".","?",";","~","`","^","[","]","%","_","{","}");
	$clearstr=array("/","\\","'","\"",",",":",">","<","&","*","(",")","@","#","+","=","$","!","|",".","?",";","~","`","^","[","]","%","{","}");//要替换的字符中不能包含下划线
	$path=str_replace($clearstr,"",$path);
	$path=preg_replace("/\s+/"," ",$path);
	$path=trim(str_replace(" ","-",$path));
	return($path);
}

/*
------------------------------------------------------
参数：
$path	路径

程序功能：清理文件夹字符串函数
------------------------------------------------------
*/
function replaceCatesName($path)
{
	$searchstr=array(">","<");
	$replacestr=array("]","[");

	$path=str_replace($searchstr,$replacestr,$path);
  
	return($path);
}

/*
------------------------------------------------------
参数：
$path	路径

程序功能：清理文件夹字符串函数(替换多个空格)
------------------------------------------------------
*/
function clearSpace($path)
{
	$path=preg_replace("/\s+/"," ",$path);

	return($path);	
}

 

/*
------------------------------------------------------
参数：
$theValue  需要替换的字符

$theType   需要替换的字符类型

程序功能：字符替换函数
------------------------------------------------------
*/
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
	case "text":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
	  break;	
	case "long":
	case "int":
	  $theValue = ($theValue !== "") ? intval($theValue) : "NULL";
	  break;
	case "double":
	  $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
	  break;
	case "date":
	  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
	  break;
	case "defined":
	  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
	  break;
  }
  return $theValue;
}

/*
------------------------------------------------------
参数：
$str_cut	需要截断的字符串
$length	 允许字符串显示的最大长度 

程序功能：截取全角和半角（汉字和英文）混合的字符串以避免乱码
------------------------------------------------------
*/
function substr_cut($str_cut,$length)
{ 
	if (strlen($str_cut) > $length)
	{ 
		for($i=0; $i < $length; $i++) 
		if (ord($str_cut[$i]) > 128)	$i++; 
		$str_cut = substr($str_cut,0,$i); 
	} 
	return $str_cut; 
}

function getimagewh($srcFile)
{
	$info = "";
	$data = GetImageSize($srcFile,$info);
	switch ($data[2]) 
	{
	 case 1:
	   if(!function_exists("imagecreatefromgif")){
		echo "你的GD库不能使用GIF格式的图片，请使用Jpeg或PNG格式！<a href='javascript:go(-1);'>返回</a>";
		exit();
	   }
	   $im = ImageCreateFromGIF($srcFile);
	   break;
	 case 2:
	   if(!function_exists("imagecreatefromjpeg")){
		echo "你的GD库不能使用jpeg格式的图片，请使用其它格式的图片！<a href='javascript:go(-1);'>返回</a>";
		exit();
	   }
	   $im = ImageCreateFromJpeg($srcFile);	
	   break;
	 case 3:
	   $im = ImageCreateFromPNG($srcFile);	
	   break;
   }
   $srcW=ImageSX($im);
   $srcH=ImageSY($im);
   $srcWH=$srcW/$srcH;
   return array($srcW,$srcH);
}
/*
------------------------------------------------------
参数：
$srcFile 源图片地址
$toW	 生成图片宽度 
$toH		 生成图片高度 
$toFile  输出目录

$sourceFile 源图片地址
$destinationWidth	 生成图片宽度 
$destinationHeight		 生成图片高度 
$destinationFile  输出文件
$useAutoPadding		是否使用自动补白，默认不使用
$qualityLevel		输出图片质量，默认8，可选值0-10
$sameSide			输出图默认高宽都限制，W 等宽， H等高

程序功能：生成缩略图
------------------------------------------------------
*/
function ImageResize($sourceFile,$destinationWidth,$destinationHeight,$destinationFile="",$useAutoPadding=false,$qualityLevel=9,$sameSide="N"){
	global $autoPaddingColor;
	
	list($sourceWidth,$sourceHeight,$sourceType)=getimagesize($sourceFile);
	$sourceRatio=$sourceWidth/$sourceHeight;
	
	switch($sourceType){
		case IMG_GIF:
			if(!function_exists("imagecreatefromgif")){
				echo "你的GD库不能使用GIF格式的图片，请使用Jpeg或PNG格式！<a href='javascript:go(-1);'>返回</a>";
				exit();
			}
			$sourceImage=imagecreatefromgif($sourceFile);
			break;
		case IMG_JPG:
		case IMG_JPEG:
			if(!function_exists("imagecreatefromjpeg")){
				echo "你的GD库不能使用jpeg格式的图片，请使用其它格式的图片！<a href='javascript:go(-1);'>返回</a>";
				exit();
			}
			$sourceImage=imagecreatefromjpeg($sourceFile);
			break;
		case 3:
			if(!function_exists("imagecreatefrompng")){
				echo "你的GD库不能使用jpeg格式的图片，请使用其它格式的图片！<a href='javascript:go(-1);'>返回</a>";
				exit();
			}
			$sourceImage=imagecreatefrompng($sourceFile);
			break;
	}
	
	if($useAutoPadding){
		$compositeImage=imagecreatetruecolor($destinationWidth,$destinationHeight);
		imagefill($compositeImage,0,0,imagecolorallocate($compositeImage,$autoPaddingColor["red"],$autoPaddingColor["green"],$autoPaddingColor["blue"]));
		if($sourceRatio>=1){
			
			$newWidth=$destinationWidth;
			$newHeight=round($newWidth/$sourceRatio);
			$coordinatesX=0;
			$coordinatesY=round(($destinationHeight-$newHeight)/2);
		}else{
			$newHeight=$destinationHeight;
			$newWidth=round($newHeight*$sourceRatio);
			$coordinatesY=0;
			$coordinatesX=round(($destinationWidth-$newWidth)/2);
		}
		if($sameSide=="W")
		{
			$newWidth=$destinationWidth;
			$newHeight=round($newWidth/$sourceRatio);
			$coordinatesX=0;
			$coordinatesY=round(($destinationHeight-$newHeight)/2);
		}
		if($sameSide=="H")
		{
			$newHeight=$destinationHeight;
			$newWidth=round($newHeight*$sourceRatio);
			$coordinatesY=0;
			$coordinatesX=round(($destinationWidth-$newWidth)/2);
		}
		imagesavealpha($sourceImage,true);
		imagealphablending($compositeImage,false);
		imagesavealpha($compositeImage,true);
		
		imagecopyresampled($compositeImage,$sourceImage,$coordinatesX,$coordinatesY,0,0,$newWidth,$newHeight,$sourceWidth,$sourceHeight);
	}else{
		if($sourceRatio>=1){
			$newWidth=$destinationWidth;
			$newHeight=round($newWidth/$sourceRatio);
		}else{
			$newHeight=$destinationHeight;
			$newWidth=round($newHeight*$sourceRatio);
		}
		
		if($sameSide=="W")
		{
				$newWidth=$destinationWidth;
				$newHeight=round($newWidth/$sourceRatio);

		}
		if($sameSide=="H")
		{
				$newHeight=$destinationHeight;
				$newWidth=round($newHeight*$sourceRatio);
		}

		$compositeImage=imagecreatetruecolor($newWidth,$newHeight);
		//if($sourceType="IMG_GIF"){  $compositeImage=ImageCreate($newWidth,$newHeight);  }
		
		imagesavealpha($sourceImage,true);
		imagealphablending($compositeImage,false);
		imagesavealpha($compositeImage,true);
		
		imagecopyresampled($compositeImage,$sourceImage,0,0,0,0,$newWidth,$newHeight,$sourceWidth,$sourceHeight);
	}
	
	switch($sourceType){
		case IMG_GIF:
			imagegif($compositeImage,$destinationFile);
			
			break;
		case IMG_JPG:
		case IMG_JPEG:
			$qualitySetting=round(($qualityLevel/10)*100);
			imagejpeg($compositeImage,$destinationFile,$qualitySetting);
			break;
		case 3:

			$qualitySetting=9-round(($qualityLevel/10)*9);
			imagepng($compositeImage,$destinationFile,$qualitySetting);
			break;
	}
	
	imagedestroy($sourceImage);
	imagedestroy($compositeImage);
}
/*
------------------------------------------------------
参数：
$srcPic 源图片文件名
$desPic 目标图片文件名
$wtString 水印字符串
$wtFont 水印字符串字体
$wtSize 水印字符串大小
$wtColor 水印字符串颜色
$wtPosition 水印字符串位置 1 2 3
$wtType 水印字符串或者图片
$picFile 水印图片文件名
$GLOBALS['wPic']   constant文件 $waterMarkPic定义的 路径
13-11-9 zhao 在ls_syscode addWatermark函数加上了扩展名
程序功能：把水印图片或字符串加到$srcPic写到$desPic
------------------------------------------------------
*/
function addWatermark($srcPic,$desPic,$wtString,$wtFont,$wtSize,$wtMargin,$wtColor,$wtPosition,$wtType,$picFile,$qualityLevel=9)
{
	list($srcwidth, $srcheight, $srctype, $srcattr) = getimagesize($srcPic);//获取文件类型
	switch($srctype) 
	{
		case 1:		$im = imageCreatefromgif($srcPic); break;
		case 2:		$im = imageCreatefromjpeg($srcPic); break;
		case 3:		$im = imageCreatefrompng($srcPic); break;
		default: return(" 测试图片文件类型错误，只能是.gif,.jpg.png");
	}
	//imagealphablending($im, true);
	//$wfilew=imagesx($im);//取得图片的宽
	//$wfileh=imagesy($im);//取得图片的高
	 if($wtType=="pic") 
	 { //图片水印  
		list($wtmwidth, $wtmheight, $wtmtype, $wtmattr)  = getimagesize($picFile);//获取文件类型
		switch($wtmtype)
		{
			//waterMarkPic 在constant中定义
			case 1:   $im2 = imagecreatefromgif($picFile);  $wtmfile=$GLOBALS['waterMarkPic'].".gif";break;  
			case 2:   $im2 = imagecreatefromjpeg($picFile); $wtmfile=$GLOBALS['waterMarkPic'].".jpg";break;
			case 3:   $im2 = imagecreatefrompng($picFile); $wtmfile=$GLOBALS['waterMarkPic'].".png";break;
			default: return("水印图片文件类型错误，只能是.gif,.jpg.png");
		}
		imagesavealpha($im2,true);  //透明处理
		imagesavealpha($im,true);
	} else {  //文字水印
		$temp = imagettfbbox(ceil($wtSize),0,"./arial.ttf",$wtString);//取得使用 TrueType 字体的文本的范围
		$wtmwidth = $temp[2] - $temp[6] + 1;   //文字宽度
		$wtmheight = $temp[3] - $temp[7] + 1;  //文字高度
		
		$fontPicFile = "images/fontwatermark.png";
		$wcolor = rgbToHex($wtColor);
		$img = imagecreatetruecolor($wtmwidth, $wtmheight);
		$color=imagecolorallocatealpha($img, 0, 0, 0, 127);
		imagecolortransparent($img,$color);
		imagealphablending($img , false);//关闭混合模式，以便透明颜色能覆盖原画板
		imagefill($img,0,0,$color);
		$textcolor=imagecolorallocatealpha($img, $wcolor['r'], $wcolor['g'], $wcolor['b'], 0);
		imagettftext($img, $wtSize, 0, 0, $wtSize, $textcolor, "./arial.ttf", $wtString);
		imagesavealpha($img , true);//设置保存PNG时保留透明通道信息   
		imagepng($img,$fontPicFile);
		imagedestroy($img);
		
		list($wtmwidth, $wtmheight, $wtmtype, $wtmattr)  = getimagesize($fontPicFile);//获取文件类型
		switch($wtmtype)
		{
			//waterMarkPic 在constant中定义
			case 1:   $im2 = imagecreatefromgif($fontPicFile);  $wtmfile=$GLOBALS['waterMarkPic'].".gif";break;  
			case 2:   $im2 = imagecreatefromjpeg($fontPicFile); $wtmfile=$GLOBALS['waterMarkPic'].".jpg";break;
			case 3:   $im2 = imagecreatefrompng($fontPicFile); $wtmfile=$GLOBALS['waterMarkPic'].".png";break;
			default: return("水印图片文件类型错误，只能是.gif,.jpg.png");
		}
		imagesavealpha($im2,true);  //透明处理
		imagesavealpha($im,true);
	}
		//copy($picFile,$wtmfile);
		$GLOBALS['wPic']=$wtmfile;

	switch($wtPosition) {
 
		case 1://为左上
			$posX = 0 + $wtMargin;
			$posY = 0 + $wtMargin;
			break;
		
		case 2://为中上
			$posX = ($srcwidth - $wtmwidth) / 2;
			$posY = 0 + $wtMargin;
			break;
	   
		case 3://为右上
			$posX = $srcwidth - $wtmwidth - $wtMargin;
			$posY = 0 + $wtMargin;
			break;
		
		case 4://中心居中
			$posX = ($srcwidth - $wtmwidth) / 2;
			$posY = ($srcheight - $wtmheight) / 2;
			break;
		
		case 5://为左下
			$posX = 0 + $wtMargin;
			$posY = $srcheight - $wtmheight - $wtMargin;
			break;
	   
		case 6://中下
			$posX = ($srcwidth - $wtmwidth) / 2;
			$posY = $srcheight - $wtmheight - $wtMargin;
			break;
		
		case 7://右下
			$posX = $srcwidth - $wtmwidth - $wtMargin;
			$posY = $srcheight - $wtmheight - $wtMargin;
			break;
		  
	}

	//读取水印文件
	if($wtType=="pic")//水印图片
	{
		//拷贝水印到目标文件
		imagecopy($im, $im2,$posX,$posY, 0, 0, $wtmwidth,$wtmheight);
	}
	else// string
	{ 
		//拷贝水印到目标文件
		imagecopy($im, $im2,$posX,$posY, 0, 0, $wtmwidth,$wtmheight);
	}
	
	
	//输出图片
	$result="";
	if($srctype==1)
	{
		$result=imagegif($im,$desPic);
	}
   if($srctype==2)
   { //同上
		$qualitySetting=round(($qualityLevel/10)*100);
		$result=imagejpeg($im,$desPic,$qualitySetting);
	}
	if($srctype==3)
	{
		$qualitySetting=9-round(($qualityLevel/10)*9);
		$result=imagepng($im,$desPic,$qualitySetting);
	}

	imagedestroy($im);
	if($result!="")
	{return(TRUE);}
	else
	{return(FALSE);}
		//echo "addwater".$srcPic.$desPic.$leftmargin.$upmargin.$watermark;
}
/*
------------------------------------------------------
参数：
$image_file  图片文件名
程序功能：判断GIF是否为动画，读取1024字节
date: 2013-10-27
------------------------------------------------------
*/
function ifanimationgif($image_file){

$fp = fopen($image_file, 'rb');

$image_head = fread($fp,1024);

fclose($fp);

return preg_match("/".chr(0x21).chr(0xff).chr(0x0b).'NETSCAPE2.0'."/",$image_head)  ? true : false;

}
/*
------------------------------------------------------
参数：
$productID 小类ID

$file  相对与于根目录的目录路径

程序功能：获取产品文件夹
------------------------------------------------------
*/
function getproductfolder($productID)
{
	require_once('conn.php');
	$opendb=new mydb();
	require('char_set.php');
	if($productID=="")	return; //没有跳过
	
	$search_subcate_sql="select * from ls_products where ID = ".$productID."";
	$search_subcate_query=$opendb->query($search_subcate_sql);
	$search_subcate_rows=mysql_fetch_assoc($search_subcate_query);
	
	if($search_subcate_rows['subcateName']=="")
	{
		if($search_subcate_rows['midcateName']=="")//??
		{
			$procate=$search_subcate_rows['cateName'];
			$procateid=$search_subcate_rows['ID'];
		
			$file=$search_subcate_rows['cateFolders'];
		
		}
		else //??+??
		{
			if($search_subcate_rows['midcateID']=="")	return; //没有跳过

			$search_cate_sql="select * from ls_products where ID = ".$search_subcate_rows['midcateID']."";
			$search_cate_query=$opendb->query($search_cate_sql);
			$search_cate_rows=mysql_fetch_assoc($search_cate_query);

		//??????
			$file=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders'];
		
		}
		
	}
	else//??+??+??
	{
	  $procate=$search_subcate_rows['subcateName'];
	  $procateid=$search_subcate_rows['ID'];
	  //????
	  	//if($search_subcate_rows['subcateID']=="" || $search_midcate_rows['midcateID']=="")	return; //没有跳过

		$search_midcate_sql="select * from ls_products where ID = ".$search_subcate_rows['subcateID']."";
		$search_midcate_query=$opendb->query($search_midcate_sql);
		$search_midcate_rows=mysql_fetch_assoc($search_midcate_query);
	  
	  //????
		$search_cate_sql="select * from ls_products where ID = ".$search_midcate_rows['midcateID']."";
		$search_cate_query=$opendb->query($search_cate_sql);
		$search_cate_rows=mysql_fetch_assoc($search_cate_query);
		
					//??????
		$file=$search_cate_rows['cateFolders']."/".$search_midcate_rows['midcateFolders']."/".$search_subcate_rows['subcateFolders'];
		 

	}
	return($file);			
}

function getproductpath($productID)
{
	require_once('conn.php');
	$opendb=new mydb();
	require('char_set.php');
	if($productID=="")	return; //没有跳过

	$search_subcate_sql="select * from ls_products where ID = ".$productID."";
	$search_subcate_query=$opendb->query($search_subcate_sql);
	$search_subcate_rows=mysql_fetch_assoc($search_subcate_query);
	
	if($search_subcate_rows['subcateName']=="")
	{
		if($search_subcate_rows['midcateName']=="")//??
		{
			$procate=$search_subcate_rows['cateName'];
			$procateid=$search_subcate_rows['ID'];
			$file=$search_subcate_rows['cateFolders'];
		}else{
			if($search_subcate_rows['midcateID']=="")	return; //没有跳过
			$search_cate_sql="select * from ls_products where ID = ".$search_subcate_rows['midcateID']."";
			$search_cate_query=$opendb->query($search_cate_sql);
			$search_cate_rows=mysql_fetch_assoc($search_cate_query);
			$file=$search_subcate_rows['midcateFolders'];
		}
	}else{
	  $procate=$search_subcate_rows['subcateName'];
	  $procateid=$search_subcate_rows['ID'];

		$search_midcate_sql="select * from ls_products where ID = ".$search_subcate_rows['subcateID']."";
		$search_midcate_query=$opendb->query($search_midcate_sql);
		$search_midcate_rows=mysql_fetch_assoc($search_midcate_query);

		$search_cate_sql="select * from ls_products where ID = ".$search_midcate_rows['midcateID']."";
		$search_cate_query=$opendb->query($search_cate_sql);
		$search_cate_rows=mysql_fetch_assoc($search_cate_query);
		
		$file=$search_subcate_rows['subcateFolders'];

	}
	return($file);			
}

/*
------------------------------------------------------
参数：

$moduleFile 链接文件名

$allpages 总页数

返回 页间导航链接

程序功能：获取产品页页间导航链接
------------------------------------------------------
*/
function getPages($moduleFile,$allpages)
{
	for ($i=0; $i< $allpages; $i++)
	{ 
	if(($allpages-$i-1)==0)
	{
		$indexp=$moduleFile;
	}
	else
	{
		$indexp=str_replace(".",($allpages-$i-1).".",$moduleFile) ;
	}


	$propage.="<div class=\"propage\"><a data-ajax='false' href=\"".$indexp."\">".($allpages-$i)."</a></div>\r\n";
			}
	if($allpages==1)
	{$propage="";}
	else
	{$propage="<div class=\"propageall\">".$propage."</div>\r\n";}
	
	return($propage);
}

function getPagess($moduleFile,$allpages,$ls_current_page)
{
	for ($i=0; $i< $allpages; $i++){
		
		if($i==0)
		{
			$indexp=$moduleFile;
		}
		else
		{
			$indexp=str_replace(".","-".$i.".",$moduleFile);
		}
		
		$a_p = $i+1;
		if($a_p != $ls_current_page){
			$propage.="<li><a href=\"".$indexp."\">".($i+1)."</a></li>\r\n";
		}else{
			$propage.="<li class=\"active\"><span>".($i+1)."</span></li>\r\n";
		}
	}
	if($ls_current_page == 1){
		$star = " class=\"disabled\" ";
	}else{
		$star = "";
	}
	if($ls_current_page == $allpages){
		$end = " class=\"disabled\" ";
	}else{
		$end = "";
	}
	if($allpages<=1)
	{$propage="";}
	else
	{$propage="<ul><li ".$star."><a href=\"".$moduleFile."\">&laquo;</a></li>".$propage."<li ".$end."><a href=\"".str_replace(".","-".($allpages-1).".",$moduleFile)."\">&raquo;</a></li></ul>\r\n";}
	
	return($propage);
}

function pathProName($proName){
	if(preg_match("/[\x7f-\xff]/", $proName)){
		$cateFolders = Pinyin($proName,1);
	}else{
		$cateFolders = trim(clearFolder(strtolower($proName)));
	}
	return $cateFolders;
}

/*
------------------------------------------------------
参数：

$products_sql 某类的sql查询串
$PageNum


程序功能：写入某类下产品页所有index文件调用（writeIndexPages）、类别详细页cateDetail.html、产品详细内容index.html,productsshow.html文件
------------------------------------------------------
*/

function writeProPageIndex($products_sql,$cateid,$midcateid,$subcateid,$translate){
	global $PageNum,$s_pro_cate,$s_cate,$s_pro2_cate,$s_pro3_cate,
	$s_pro4_cate,$pro_cate,$cate,$pro2_cate,$pro3_cate,$pro4_cate,$menu,
	$menu_pro,$menu_pro2,$menu_pro3,$menu_pro4,$showproductsFolders,$lsproshowmenu,$foot,
	$SmallFoldersProducts,$BigFoldersProducts,$minCateDetailLength,$detail,$foot,$menuListscateid,$DetailPage,
	$ls_about,$ls_news,$ls_faq,$ls_classpro,$ls_hotpro,$ls_designby,$ls_newsdongtai,$ls_newsgonggao,$ls_newstieshi,$ls_procurrentpage,
	$ls_newsall2,$ls_newsdongtai2,$ls_newsgonggao2,$ls_newstieshi2,
	$ls_newsall3,$ls_newsdongtai3,$ls_newsgonggao3,$ls_newstieshi3,
	$ls_newsall4,$ls_newsdongtai4,$ls_newsgonggao4,$ls_newstieshi4,$s_site_cate,$site_cate1,$s_site2_cate,$s_site3_cate,$s_site4_cate,
	$ls_link,$link,$pro_link,$pro2_link,$pro3_link,$pro4_link,$ls_catenews,$ls_addprolink,$ls_addnewprolink,
	$pro_revo,$pro2_revo,$pro3_revo,$pro4_revo,$facebook_twitter,$facebook_twitter_share,
	$productDescriptionTitle,$productshowstyl, $s_p_cate, $s_p0_cate, $s_p1_cate, $s_p2_cate, $s_p3_cate, $s_p4_cate, $ls_h1_news, $ls_h2_news, $ls_h3_news, $ls_h4_news,$languages0,$languages,$languages2,$languages3,$languages4;
	//echo $menuListscateid."writeProPageIndex";
	//echo $pro_revo." - - -  - - - - - -  - - - ".$pro2_revo;
	$mynum=0;//总产品数
	$allpages=0;//共有页数
	$pathprofilename = ""; //新型产品详细页文件名
	
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	
	if($lang != "en"){
		$lan = $lang_cn;
	}else{
		$lan = $lang_en;
	}
	
	//echo "=======".$products_sql."===========";
	
	$tem_sql="select * from ls_config order by ID";	
	$tem_query=$opendb->query($tem_sql);
	$row=mysql_fetch_array($tem_query);
	$templates_var = $row['templates'];
	//echo $templates_var;

	//if $mynum=0 or $detail>$minCateDetailLength write index.html 没有产品或者类别详细页面有内容只生成 类别单页
	$detail="";  //set the cat subcat midcate detail flag

	$motif_sql="select * from ls_motif where enable=1 order by Num desc ";
	$motif_query=$opendb->query($motif_sql);
	
	$s_motif_cate.="";
	while($motif_rows=mysql_fetch_assoc($motif_query))
	{
		if($motif_rows['motif_href'] !=''){
			$s_motif_cate.="<div class=\"pic_box\"><a href=\"".$motif_rows['motif_href']."\" style=\"background-image: url(../".$MotifFolders."/".$BigFoldersProducts."/".$motif_rows['motifPic']."); background-repeat: no-repeat; background-position: center top; background-color:#dcdcdc;\" ></a></div>";
		}else{
			$s_motif_cate.="<div class=\"pic_box\"><a href=\"javascript:void(0)\" style=\"background-image: url(../".$MotifFolders."/".$BigFoldersProducts."/".$motif_rows['motifPic']."); background-repeat: no-repeat; background-position: center top; background-color:#dcdcdc;\" ></a></div>";
		}
		
	}
	$s_motif_cate.="";
	
	$s_m_cate=str_replace("../","../",$s_motif_cate);//cate
	$s_m2_cate=str_replace("../","../../",$s_motif_cate);//pro2_cate
	$s_m3_cate=str_replace("../","../../",$s_motif_cate);//pro3_cate
	$s_m4_cate=str_replace("../","../../",$s_motif_cate);//pro4_cate
	

	if($cateid!="" && $midcateid=="" && $subcateid=="")//大类 catedetial
	{
		$sqldetail="select * from ls_products where ID =".$cateid." ";
		$querydetail=$opendb->query($sqldetail);
		$myrowsdetail=mysql_fetch_assoc($querydetail);
		if($myrowsdetail['cateDetail']!="")
		{$detail=htmlspecialchars_decode($myrowsdetail['cateDetail'],ENT_QUOTES);
		}
		$procate=$myrowsdetail['cateName'];
		$indicatebar="<li><a href=\"../index.html\">".$lan['home']."</a></li> <li><a href=\"../prolist.html\">".$lan['products']."</a></li> <li><a href=\"../".$myrowsdetail['cateFolders']."/".$myrowsdetail['cateFolders'].".html\"><translate>".$myrowsdetail['cateName']."</translate></a></li>";

		$catetitle=$myrowsdetail['cateTitle'];
		$cateKeywords=$myrowsdetail['cateKeywords'];
		$cateDescription=$myrowsdetail['cateDescription'];
		$banner=$myrowsdetail['catePagePic'];
		$file=$myrowsdetail['cateFolders']."/".$myrowsdetail['cateFolders'].".html";
		$lsbrief=$myrowsdetail['cateBrief'];
		$echoname="大类".$myrowsdetail['cateName'];
		$prolistfilename = $myrowsdetail['cateFolders'];
		
		$url="";
		$leftcate=$pro_cate;
		$s_cate=$s_pro_cate;			//左侧产品类别
		$s_news=$ls_h1_news;			//新闻
		$s_p_cate=$s_p0_cate;			//左侧产品类别
		$ls_languages=$languages;		//语言国旗
		$s_f_cate=get_pro_cate(1);
		
		$facebook_twitter = str_replace("YOUR-FACEBOOK",$row['facebook'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-TWITTER",$row['twitter'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-LINKEDIN",$row['linkedin'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-GOOGLE",$row['google'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-PINTEREST",$row['pinterest'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-YOUTUBE",$row['youtube'],$facebook_twitter);
		
		$ls_facebook_twitter = str_replace("../","../",$facebook_twitter);//cate
		$ls_facebook_twitter2 = str_replace("../","../",$facebook_twitter);//cate
		
		$site_cate = $s_site2_cate;
		$site_cate_pro = $s_site_cate;
		
		$leftprocate=$pro2_cate;
		$lspro_menu=$menu_pro;
		$lsproshowmenu=$menu_pro2;
		$ls_link=$pro_link;
		$lspro_link=$pro2_link;
		$ls_revo=$pro_revo;
		$lspro_revo=$pro2_revo;
		$ls_motif=$s_m_cate;   //产品相册主题图片
		$lspro_motif=$s_m2_cate;  //产品详细页主题图片

		$ls_newsdongtai=$ls_newsdongtai2;
		$ls_newstieshi=$ls_newstieshi2;
		$ls_newsgonggao=$ls_newsgonggao2;
		$ls_newsall=$ls_newsall2;
		
		
		//中类代表图
		$midcate_pic_sql="SELECT * FROM `ls_products` WHERE `midcateID`=".$cateid."  order by Num";
		$midcate_pic_query=$opendb->query($midcate_pic_sql);
		
		switch($catedetailStytle){
			
			case "selectProducts":
			
				$mid_pic = "<div class=\"row pro_list\">";
				while($midcate_pic_rows=mysql_fetch_assoc($midcate_pic_query)){
					if($midcate_pic_rows['catePic'] != null){
						$mid_pic .= "<div class=\"col-xs-4\"><div class=\"thumbnail\"><div class=\"img-pic\"><a href=\"".$midcate_pic_rows['midcateFolders']."/".$midcate_pic_rows['midcateFolders'].".html\"><img src=\"".$midcate_pic_rows['midcateFolders']."/".$midcate_pic_rows['catePic']."\" name=\"imgs\" alt=\"<translate>".$midcate_pic_rows['midcateName']."</translate>\" title=\"<translate>".$midcate_pic_rows['midcateName']."</translate>\"/></a></div><div class=\"caption pro-name\"><a href=\"".$midcate_pic_rows['midcateFolders']."/".$midcate_pic_rows['midcateFolders'].".html\"><translate>".$midcate_pic_rows['midcateName']."</translate></a></div></div></div>";
					}
				}
				$mid_pic .= "</div>";//echo $mid_pic;
			
			break;
			
			case "allCateProducts":
			
				$mid_pic = "<div class=\"row pro_list\" id=\"itemContainer\">";
				while($midcate_pic_rows=mysql_fetch_assoc($midcate_pic_query)){
					$catedetail_sql="SELECT * FROM `ls_products` WHERE `productID`=".$midcate_pic_rows['ID']." order by Num ";
					$catedetail_query=$opendb->query($catedetail_sql);
					while($catedetail_rows=mysql_fetch_assoc($catedetail_query)){
						$mid_pic .= "<div class=\"col-xs-4\"><div class=\"thumbnail\"><div class=\"img-pic\"><a href=\"".$midcate_pic_rows['midcateFolders']."/".pathProName($catedetail_rows['productName'])."-".$catedetail_rows['ID'].".html\"><img src=\"".$midcate_pic_rows['midcateFolders']."/".$SmallFoldersProducts."/".$catedetail_rows['productPic']."\" name=\"imgs\" alt=\"<translate>".$catedetail_rows['productItemNo']."</translate>\" title=\"<translate>".$catedetail_rows['productItemNo']."</translate>\" /></a></div><div class=\"caption pro-name\"><a href=\"".$midcate_pic_rows['midcateFolders']."/".pathProName($catedetail_rows['productName'])."-".$catedetail_rows['ID'].".html\"><translate>".$catedetail_rows['productItemNo']."</translate></a></div></div></div>";
					}
				}
				$mid_pic .= "</div>";//echo $mid_pic;
			
			break;
		}

		$behalf = $mid_pic;
		
	}

	if($cateid!="" && $midcateid!="" && $subcateid=="")//中类 midcatedetial
	{
		$sqldetail="select * from ls_products where ID =".$midcateid." ";
		$querydetail=$opendb->query($sqldetail);
		$myrowsdetail=mysql_fetch_assoc($querydetail);
		if($myrowsdetail['midcateDetail']!=""){
			$detail=htmlspecialchars_decode($myrowsdetail['midcateDetail'],ENT_QUOTES);
		}
		$procate=$myrowsdetail['midcateName'];
		
		$catetitle=$myrowsdetail['cateTitle'];
		$cateKeywords=$myrowsdetail['cateKeywords'];
		$cateDescription=$myrowsdetail['cateDescription'];

		$sqldetail2="select * from ls_products where ID =".$myrowsdetail['midcateID']." ";
		$querydetail2=$opendb->query($sqldetail2);
		$myrowsdetail2=mysql_fetch_assoc($querydetail2);
		
		$sql_path="select * from ls_products where midcateID =".$myrowsdetail['midcateID']." ORDER BY Num ASC ";
		$query_path=$opendb->query($sql_path);
		$rows_path=mysql_fetch_assoc($query_path);
		
		$catetitle=($catetitle=="")?$myrowsdetail2['cateTitle']:$catetitle;
		$cateKeywords=($cateKeywords=="")?$myrowsdetail2['cateKeywords']:$cateKeywords;
		$cateDescription=($cateDescription=="")?$myrowsdetail2['cateDescription']:$cateDescription;
		
		$banner="../".$myrowsdetail2['catePagePic'];
		$file=$myrowsdetail2['cateFolders']."/".$myrowsdetail['midcateFolders']."/".$myrowsdetail['midcateFolders'].".html";
		$detailsfile2="../".$templates_var."/catedetail.html";
		if(file_exists($detailsfile2)){
			$path_pro=$myrowsdetail2['cateFolders']."/".$myrowsdetail2['cateFolders'].".html";
		}else{
			$path_pro=$myrowsdetail2['cateFolders']."/".$rows_path['midcateFolders']."/".$rows_path['midcateFolders'].".html";
		}
		$lsbrief=$myrowsdetail['midcateBrief'];
		$echoname=" 中类".$myrowsdetail['midcateName'];
		$indicatebar="<li><a href=\"../../index.html\">".$lan['home']."</a></li> <li><a href=\"../../{ls_addprolink}\">".$lan['products']."</a></li> <li><a href=\"../../".$path_pro."\"><translate>".$myrowsdetail2['cateName']."</translate></a></li> <li><a href=\"../../".$myrowsdetail2['cateFolders']."/".$myrowsdetail['midcateFolders']."/".$myrowsdetail['midcateFolders'].".html\"><translate>".$myrowsdetail['midcateName']."</translate></a></li>";
		$prolistfilename = $myrowsdetail['midcateFolders'];
	
		$url="../";
		$leftcate=$pro2_cate;
		$s_cate=$s_pro2_cate;			//左侧产品类别
		$s_news=$ls_h2_news;			//新闻
		$s_p_cate=$s_p2_cate;			//左侧产品类别
		$ls_languages=$languages2;      //语言国旗
		$s_f_cate=get_pro_cate(2);
		
		$facebook_twitter = str_replace("YOUR-FACEBOOK",$row['facebook'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-TWITTER",$row['twitter'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-LINKEDIN",$row['linkedin'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-GOOGLE",$row['google'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-PINTEREST",$row['pinterest'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-YOUTUBE",$row['youtube'],$facebook_twitter);
		
		$ls_facebook_twitter = str_replace("../","../../",$facebook_twitter);//cate
		$ls_facebook_twitter2 = str_replace("../","../../",$facebook_twitter);//cate
		
		$site_cate = $s_site3_cate;
		$site_cate_pro = $s_site2_cate;
		
		$leftprocate=$pro3_cate;
		$lspro_menu=$menu_pro2;
		$lsproshowmenu=$menu_pro3;
		$ls_link=$pro2_link;
		$lspro_link=$pro3_link;
		$ls_revo=$pro2_revo;
		$lspro_revo=$pro3_revo;
		$ls_motif=$s_m2_cate;   //产品相册主题图片
		$lspro_motif=$s_m3_cate;  //产品详细页主题图片

		$ls_newsdongtai=$ls_newsdongtai3;
		$ls_newstieshi=$ls_newstieshi3;
		$ls_newsgonggao=$ls_newsgonggao3;
		$ls_newsall=$ls_newsall3;
		
		
		//小类代表图
		$subcate_pic_sql="SELECT * FROM `ls_products` WHERE `subcateID`=".$midcateid."";
		$subcate_pic_query=$opendb->query($subcate_pic_sql);
		$sub_pic = "<ul class=\"pro_list\">";
		while($subcate_pic_rows=mysql_fetch_assoc($subcate_pic_query)){
			if($subcate_pic_rows['catePic'] != null){
				$sub_pic .= "<li><a href=\"".$subcate_pic_rows['subcateFolders']."/index.html\"><img src=\"".$subcate_pic_rows['subcateFolders']."/".$subcate_pic_rows['catePic']."\"  name=\"imgs\" alt=\"".$products_rows['productItemNo']."\" /></a>".$subcate_pic_rows['subcateName']."</li>";
			}
		}
		
		$sub_pic .= "</ul>";
		//echo "<h1>".$sub_pic."</h1>dddd";
		$behalf = $sub_pic;
		
	}				

	if($cateid!="" && $midcateid!="" && $subcateid!="")//小类 subcatedetial
	{
		$sqldetail="select * from ls_products where ID =".$subcateid." ";
		$querydetail=$opendb->query($sqldetail);
		$myrowsdetail=mysql_fetch_assoc($querydetail);
		if($myrowsdetail['subcateDetail']!="")
		{$detail=htmlspecialchars_decode($myrowsdetail['subcateDetail'],ENT_QUOTES);
		}
		$procate=$myrowsdetail['subcateName'];
		
		$catetitle=$myrowsdetail['cateTitle'];
		$cateKeywords=$myrowsdetail['cateKeywords'];
		$cateDescription=$myrowsdetail['cateDescription'];
		
		$sqldetail2="select * from ls_products where ID =".$myrowsdetail['subcateID']." ";
		$querydetail2=$opendb->query($sqldetail2);
		$myrowsdetail2=mysql_fetch_assoc($querydetail2);
		
		$catetitle=($catetitle=="")?$myrowsdetail2['cateTitle']:$catetitle;
		$cateKeywords=($cateKeywords=="")?$myrowsdetail2['cateKeywords']:$cateKeywords;
		$cateDescription=($cateDescription=="")?$myrowsdetail2['cateDescription']:$cateDescription;

		$sqldetail3="select * from ls_products where ID =".$myrowsdetail2['midcateID']." ";
		$querydetail3=$opendb->query($sqldetail3);
		$myrowsdetail3=mysql_fetch_assoc($querydetail3);

		$catetitle=($catetitle=="")?$myrowsdetail3['cateTitle']:$catetitle;
		$cateKeywords=($cateKeywords=="")?$myrowsdetail3['cateKeywords']:$cateKeywords;
		$cateDescription=($cateDescription=="")?$myrowsdetail3['cateDescription']:$cateDescription;
		
		$banner="../../".$myrowsdetail3['catePagePic'];
		$file=$myrowsdetail3['cateFolders']."/".$myrowsdetail2['midcateFolders']."/".$myrowsdetail['subcateFolders']."/".$myrowsdetail['subcateFolders'].".html";
		$lsbrief=$myrowsdetail['subcateBrief'];
		$echoname=" 小类".$myrowsdetail['subcateName'];
			$indicatebar="<li><a href=\"../../index.html\">".$lan['home']."</a></li> <li><a href=\"../../../{ls_addprolink}\">".$lan['products']."</a></li> <li><a href=\"../../".$path_pro."\"><translate>".$myrowsdetail3['cateName']."</translate></a></li> <li><a href=\"../../".$myrowsdetail2['cateFolders']."/".$myrowsdetail['midcateFolders']."/".$myrowsdetail['midcateFolders'].".html\"><translate>".$myrowsdetail2['midcateName']."</translate></a></li> <li><a href=\"../../../".$myrowsdetail3['cateFolders']."/".$myrowsdetail2['midcateFolders']."/".$myrowsdetail['subcateFolders']."/".$myrowsdetail['subcateFolders'].".html\"><translate>".$myrowsdetail['subcateName']."</translate></a></li>";
			
		//$indicatebar="Home -> ".$myrowsdetail3['cateName']." -> ".$myrowsdetail2['midcateName']." -> ".$myrowsdetail['subcateName'];
		$prolistfilename = $myrowsdetail['subcateFolders'];

		$url="../../";
		$s_cate=$s_pro3_cate;			//左侧产品类别
		$s_news=$ls_h3_news;			//新闻
		$s_p_cate=$s_p3_cate;			//左侧产品类别
		$ls_languages=$languages3;		//语言国旗
		$s_f_cate=get_pro_cate(3);
		$site_cate = $s_site4_cate;
		$site_cate_pro = $s_site3_cate;
		
		$facebook_twitter = str_replace("YOUR-FACEBOOK",$row['facebook'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-TWITTER",$row['twitter'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-LINKEDIN",$row['linkedin'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-GOOGLE",$row['google'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-PINTEREST",$row['pinterest'],$facebook_twitter);
		$facebook_twitter = str_replace("YOUR-YOUTUBE",$row['youtube'],$facebook_twitter);
		
		$ls_facebook_twitter = str_replace("../","../../../",$facebook_twitter);//cate
		$ls_facebook_twitter2 = str_replace("../","../../../",$facebook_twitter);//cate
		
		$leftcate=$pro3_cate;
		$leftprocate=$pro4_cate;
		$lspro_menu=$menu_pro3;
		$lsproshowmenu=$menu_pro4;
		$ls_link=$pro3_link;
		$lspro_link=$pro4_link;
		$ls_revo=$pro3_revo;
		$lspro_revo=$pro4_revo;		
		$ls_motif=$s_m3_cate;   //产品相册主题图片
		$lspro_motif=$s_m4_cate;  //产品详细页主题图片

		$ls_newsdongtai=$ls_newsdongtai4;
		$ls_newstieshi=$ls_newstieshi4;
		$ls_newsgonggao=$ls_newsgonggao4;
		$ls_newsall=$ls_newsall4;
		
	}

		//if(strlen($detail)>$minCateDetailLength)  // 叶类小于预定长度将不生成,否则生成一个详细页
		if($cateDetailPageCreate)
		{
			$echoname="详细: ".$echoname;
			
			//echo "dfdfdfdfdfd".$templates_var."dfdfdfdfdf";exit;
			
			$index_path2="../".$templates_var."/catedetail.html";	//类详细页面
			$detailsfile=str_replace("index.html","indexdetails.html",$file);
						
			writeIndexPages($index_path2,$catetitle,$cateKeywords,$cateDescription,$url,$banner,$leftcate,$lspro_menu,
			$lsbrief,$procate,$procateid,$propage,$pro,$detailsfile,$echoname,$mynum,$allpages,$detail,$s_cate,$s_news,$s_p_cate,$ls_languages,$s_f_cate,$site_cate_pro,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf,$ls_facebook_twitter2,$translate);
			//echo $detail;
			
		}
		if($DetailPage==1)		//0 叶类生成详细说明页面，函数继续执行 1枝类生成详细说明页面，函数返回
		{
			$DetailPage=0; //reset flag
			return;
		}		
		//产品排序
		$sort='Num';
		$products_sql.=" and enable=1 order by $sort asc ";
		$result=$opendb->query($products_sql);
		$result2=$opendb->query($products_sql);		//for the browseNo
		$mynum = mysql_num_rows($result);//总产品数
		// 每页数量
		$onepage = $PageNum; 
		//共有页数
		$allpages = ceil($mynum/$onepage);
		if($mynum==0)  // 没有产品
		{
			$echoname="无产品: ".$echoname;
			$mynum=0;
			$allpages=1;
			
			
			$index_path="../".$templates_var."/catedetail.html";	//没产品，输出 详细页或者 产品页没内容

			if(is_file($index_path)){}
			else
			{$index_path="../".$templates_var."/products.html";}
			writeIndexPages($index_path,$catetitle,$cateKeywords,$cateDescription,$url,$banner,$leftcate,$lspro_menu,
			$lsbrief,$procate,$procateid,$propage,$pro,$file,$echoname,$mynum,$allpages,$detail,$s_cate,$s_news,$s_p_cate,$ls_languages,$s_f_cate,$site_cate_pro,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf,$ls_facebook_twitter2,$translate);
			return;
		}
		
			//end  没有产品或者类别详细页面有内容只生成 类别单页
			
			//echo $products_sql."共有".$mynum."个产品。可以生成".$allpages."页.每页".$onepage."个<br>";
			
			//页码计算
			//$propage=getpages("index.html",$allpages);
			//页码计算
			
			$j=1;
			
			for ($iii=0; $iii<$allpages; $iii++)
			{ 
				$ls_procurrentpage="";
				if ($iii == 0)
				{ 
				$indexpath = $prolistfilename.".html";
				} 
				else 
				{ 
				  $indexpath = $prolistfilename."-".$iii.".html";
				}
				$start = $iii * $onepage;
				if($allpages!=1){
					//$ls_procurrentpage="[".($iii+1)."]";		//当前页码
					$ls_current_page=$iii+1;
				}
				$pro="<div class=\"row pro_list\">";
		 //查询产品
		 
			 $products_sql2=$products_sql." limit ".$start.",".$onepage." ";
			 //echo $products_sql2."<br>";
			 $products_query=$opendb->query($products_sql2);
			 //echo "$products_sql2";
			 while($products_rows=mysql_fetch_assoc($products_query))
			 {
				//查询小类
				$search_subcate_sql="select * from ls_products where ID = ".$products_rows['productID']."";
				$search_subcate_query=$opendb->query($search_subcate_sql);
				$search_subcate_rows=mysql_fetch_assoc($search_subcate_query);

				if($search_subcate_rows['subcateName']=="")
				{

					if($search_subcate_rows['midcateName']=="")//大类
					{						
					$procate=$search_subcate_rows['cateName'];//cate name in products 
					$procateid=$search_subcate_rows['ID'];
						
					$imgpic=$SmallFoldersProducts."/".$products_rows['productPic'];
						//生成文件地址
					$file=$search_subcate_rows['cateFolders']."/".$indexpath;
						//生成大图地址
						
//$profile=$search_subcate_rows['cateFolders']."/".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html";
					$pathprofilename = $search_subcate_rows['cateFolders'];
					$pathprofile = "../";
					$profile=$search_subcate_rows['cateFolders']."/".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html";
					$proFiles=$search_subcate_rows['cateFolders']."/";
						
					$catetitle=$search_subcate_rows['cateTitle'];
					$cateKeywords=$search_subcate_rows['cateKeywords'];
					$cateDescription=$search_subcate_rows['cateDescription'];
					$banner=$search_subcate_rows['catePagePic'];
					$lsbrief=$search_subcate_rows['cateBrief'];
						
					$url="";
					$s_cate=$s_pro_cate;
					$s_news=$ls_h1_news;			//新闻
					$s_p_cate=$s_p0_cate;
					$ls_languages = $languages;
					$s_f_cate=get_pro_cate(1);
					$s_procate=$s_pro_cate;	//左侧产品类别
					$ss_p_cate=$s_p_cate;
					$ss_f_cate=get_pro_cate(2);
					$leftcate=$pro_cate;
					$leftprocate=$pro2_cate;
					$lspro_menu=$menu_pro;
					$lsproshowmenu=$menu_pro2;
					$ls_link=$pro_link;
					$lspro_link=$pro2_link;
					$ls_revo=$pro_revo;
					$lspro_revo=$pro2_revo;
					}
					else //大类+中类
					{
					
					$catetitle=$search_subcate_rows['cateTitle'];
					$cateKeywords=$search_subcate_rows['cateKeywords'];
					$cateDescription=$search_subcate_rows['cateDescription'];
					
					$procate=$search_subcate_rows['midcateName'];
					$search_cate_sql="select * from ls_products where ID = ".$search_subcate_rows['midcateID']."";
					$search_cate_query=$opendb->query($search_cate_sql);
					$search_cate_rows=mysql_fetch_assoc($search_cate_query);

					$imgpic=$SmallFoldersProducts."/".$products_rows['productPic'];
					//生成文件地址
					$file=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders']."/".$indexpath;
					//生成大图文件地址
					//$profile=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders']."/".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html";
					$pathprofilename = $search_subcate_rows['midcateFolders'];
					$pathprofile = "../../";
					$profile=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders']."/".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html";
					$proFiles=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders']."/";

					$catetitle=($catetitle=="")?$search_cate_rows['cateTitle']:$catetitle;
					$cateKeywords=($cateKeywords=="")?$search_cate_rows['cateKeywords']:$cateKeywords;
					$cateDescription=(($cateDescription==" ")||($cateDescription==""))?$search_cate_rows['cateDescription']:$cateDescription;
					
					$banner="../".$search_cate_rows['catePagePic'];
					$lsbrief=$search_subcate_rows['midcateBrief'];
					$url="../";
					$s_cate=$s_pro2_cate;	//左侧产品类别
					$s_news=$ls_h2_news;			//新闻
					$s_p_cate=$s_p2_cate;
					$ls_languages = $languages2;
					$s_f_cate=get_pro_cate(2);
					$s_procate=$s_pro2_cate;	//左侧产品类别
					$ss_p_cate=$s_p2_cate;
					$ss_f_cate=get_pro_cate(3);
					$leftcate=$pro2_cate;
					$leftprocate=$pro3_cate;
					$lspro_menu=$menu_pro2;
					$lsproshowmenu=$menu_pro3;
					$ls_link=$pro2_link;
					$lspro_link=$pro3_link;
					$ls_revo=$pro2_revo;
					$lspro_revo=$pro3_revo;						
					}
						
				}
				else//大类+中类+小类
				{
					
					$catetitle=$search_subcate_rows['cateTitle'];
					$cateKeywords=$search_subcate_rows['cateKeywords'];
					$cateDescription=$search_subcate_rows['cateDescription'];
					
					$procate=$search_subcate_rows['subcateName'];
					$procateid=$search_subcate_rows['ID'];
				  //查询中类
					$search_midcate_sql="select * from ls_products where ID = ".$search_subcate_rows['subcateID']."";
					$search_midcate_query=$opendb->query($search_midcate_sql);
					$search_midcate_rows=mysql_fetch_assoc($search_midcate_query);
					
					$catetitle=($catetitle=="")?$search_midcate_rows['cateTitle']:$catetitle;
					$cateKeywords=($cateKeywords=="")?$search_midcate_rows['cateKeywords']:$cateKeywords;
					$cateDescription=(($cateDescription==" ")||($cateDescription==""))?$search_midcate_rows['cateDescription']:$cateDescription;
					  
				  //查询大类
					$search_cate_sql="select * from ls_products where ID = ".$search_midcate_rows['midcateID']."";
					$search_cate_query=$opendb->query($search_cate_sql);
					$search_cate_rows=mysql_fetch_assoc($search_cate_query);
					
					$catetitle=($catetitle=="")?$search_cate_rows['cateTitle']:$catetitle;
					$cateKeywords=($cateKeywords=="")?$search_cate_rows['cateKeywords']:$cateKeywords;
					$cateDescription=(($cateDescription==" ")||($cateDescription==""))?$search_cate_rows['cateDescription']:$cateDescription;
						
					$imgpic=$SmallFoldersProducts."/".$products_rows['productPic'];
					//生成文件地址
					$file=$search_cate_rows['cateFolders']."/".$search_midcate_rows['midcateFolders']."/".$search_subcate_rows['subcateFolders']."/".$indexpath;
					//生成大图地址
					//$profile=$search_cate_rows['cateFolders']."/".$search_midcate_rows['midcateFolders']."/".$search_subcate_rows['subcateFolders']."/".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html";
					$pathprofilename = $search_subcate_rows['subcateFolders'];
					$pathprofile = "../../../";
					$profile=$search_cate_rows['cateFolders']."/".$search_midcate_rows['midcateFolders']."/".$search_subcate_rows['subcateFolders']."/".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html";
					$proFiles=$search_cate_rows['cateFolders']."/".$search_midcate_rows['midcateFolders']."/".$search_subcate_rows['subcateFolders']."/";
					
					$banner="../../".$search_cate_rows['catePagePic'];
					$lsbrief=$search_subcate_rows['subcateBrief'];
					
					$url="../../";
					$s_cate=$s_pro3_cate;				//左侧产品类别
					$s_news=$ls_h3_news;			//新闻
					$s_p_cate=$s_p3_cate;
					$ls_languages = $languages3;
					$s_f_cate=get_pro_cate(3);
					$s_procate=$s_pro3_cate;				//左侧产品类别
					$ss_p_cate=$s_p3_cate;
					$ss_f_cate=get_pro_cate(4);
					$leftcate=$pro3_cate;
					$leftprocate=$pro4_cate;
					$lspro_menu=$menu_pro3;
					$lsproshowmenu=$menu_pro4;
					$ls_link=$pro3_link;
					$lspro_link=$pro4_link;
					$ls_revo=$pro3_revo;
					$lspro_revo=$pro4_revo;					
					$ls_motif=$s_m3_cate;   //产品相册主题图片
					$lspro_motif=$s_m4_cate;  //产品详细页主题图片
				}
				
				
				//产品
				//if($i==0){
					/*$pro.="<li><a href=\"".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" target=\"_blank\"><img src=\"".$imgpic."\" alt=\"".$products_rows['productName']."\" /></a><a href=\"".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" target=\"_blank\">".$products_rows['productName']."</a><a href=\"".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" target=\"_blank\">".$products_rows['productItemNo']."</a></li>";*/
				switch($productshowstyle)
				{
					case "name":
					$pro.="<li id='pro_list_li_name'>".(file_exists("../Templates1/images/name_prefix.gif")?"<img src=\"{ls_url}../Templates1/images/name_prefix.gif\" id='pro_list_li_img_name'/>":'').
					"\r\n<a id='pro_list_li_a_name' href=\"".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\">".$products_rows['productItemNo']."</a></li>\r\n";
					break;
					
					case "list":
						$pro.="<div class=\"col-lg-4\"><div class=\"thumbnail\"><div class=\"img-pic\"><a href=\"".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html\" alt=\"<translate>".$products_rows['productItemNo']."</translate>\" class=\"c-img-height\" ><img src=\"".$imgpic."\" alt=\"<translate>".$products_rows['productItemNo']."</translate>\" title=\"<translate>".$products_rows['productItemNo']."</translate>\" /></a></div><div class=\"caption pro-name\"><table align='center'><tr height='40'><td><a href=\"".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html\" alt=\"<translate>".$products_rows['productItemNo']."</translate>\" title='<translate>".$products_rows['productItemNo']."</translate>' ><translate>".$products_rows['productItemNo']."</translate></a></td></tr></table></div></div></div>";

					//$pro.="<li><a href=\"".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" ><img src=\"".$imgpic."\" alt=\"".$products_rows['productItemNo']."\" /></a><a href=\"".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" class='pn' >".$products_rows['productItemNo']."</a></li>";
					
					break;
					
					case "style4":
					$pro.="<li id='pro_list_li_style4' ><a id='pro_list_li_a_name' href=\"".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\">".$products_rows['productItemNo']."</a></li>\r\n";
					break;
					
					case "style5":
					$pro.="<li id='pro_list_li_style4' ><a id='pro_list_li_a_name' href=\"".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\">".$products_rows['productItemNo']."</a></li>\r\n";
					break;
					
					
					case "":
					case "gallary":
					default:
					$pro.="<li><a href=\"".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\"><img width=\"".($showSmallPicW!=""?$showSmallPicW:'188')."\" src=\"".$imgpic."\" alt=\"".$products_rows['productItemNo']."\" /></a>".$products_rows['productItemNo']."</li>\r\n";
					
				}
				//}else{
					//$pro.="<li><a href=\"".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\"><img src=\"".$imgpic."\" alt=\"".$products_rows['productItemNo']."\" /></a>".$products_rows['productItemNo']."</li>";
				//}				   
			
		//页码计算
		$propage=getPagess($pathprofilename.".html",$allpages,$ls_current_page);


		$proshow_path="../".$templates_var."/productsshow.html";			//大图模板地址
		if(!file_exists($proshow_path))
		{
			echo "模板文件".$proshow_path."不存在！请设计好模板后重新生成。</br></br>";
			return;
		}
		
			
			$ls_menu=$lsproshowmenu;	//主菜单
//			$ls_protitle=$catetitle;				  //title
//			$ls_prokeywords=$cateKeywords;			//Keywords
//			$ls_description=$cateDescription;		//Description
			$ls_protitle=$products_rows['productTitle']==""?$catetitle:$products_rows['productTitle'];				  		//产品title
			$ls_prokeywords=$products_rows['productKeywords']==""?$cateKeywords:$products_rows['productKeywords'];			//产品Keywords
			$ls_description=$products_rows['productDescription']==""?$cateDescription:$products_rows['productDescription'];		//产品Description
			$ls_prourl=$url;
			$ls_s_cate=$s_procate;				//左侧产品类别
			$ls_s_news=$s_news;				//新闻
			$ls_p_cate=$ss_p_cate;				//左侧产品类别
			$ls_f_cate=$ss_f_cate;
			$ls_cate=$leftcate;
			$needleonmouseover="<ul  id=\"menuLists".$menuListscateid."\" style=\"display:none;\">\r\n";	//替换悬停菜单内容
			$replaceonmouseover="<ul  id=\"menuLists".$menuListscateid."\" style=\"display:block;\">\r\n";

			if($menuListscateid!=0){$ls_s_cate=str_replace($needleonmouseover,$replaceonmouseover,$ls_s_cate);}
			//echo "list1--".$menuListscateid."--pp";
			$ls_probanner=$banner;						//大类主体图
			$ls_procate=$leftprocate;						//左侧产品类别
			
			if(strpos($indicatebar, "../../") !== false){
				$ls_indicatebar=str_replace("../../","../../",$indicatebar);
			}else{
				$ls_indicatebar=str_replace("../","../",$indicatebar);
			}
			//相关产品 -- 前10产品与后10产品   --有图片
			$related_products = "";
			//前10个产品
			$p_sql="select * from ls_products where productID = ".$products_rows['productID']." and ID > ".$products_rows['ID']." ORDER BY ID asc ";
			$p_query=$opendb->query($p_sql);
			$p_num = mysql_num_rows($p_query);
			
			$n_sql="select * from ls_products where productID = ".$products_rows['productID']." and ID < ".$products_rows['ID']." ORDER BY ID desc";
			$n_query=$opendb->query($n_sql);
			$n_num = mysql_num_rows($n_query);
			$limitnum = 0;
			if($p_num < $related_products_num){
				$limitnum = $related_products_num + ($related_products_num - $p_num);
			}elseif($n_num < $related_products_num){
				$limitnum = $related_products_num + ($related_products_num - $n_num);
			}else{
				$limitnum = $related_products_num;
			}
			
			$related_sql="select * from ls_products where productID = ".$products_rows['productID']." and ID > ".$products_rows['ID']." ORDER BY ID asc LIMIT 0 , ".$limitnum;
			$related_query=$opendb->query($related_sql);
			$related_products.="<div  class=\"row related\">";
			while($related_rows=mysql_fetch_array($related_query)){
				$related_products.="<div class=\"col-lg-4 col-md-4 col-sm-6 col-xs-12\"><div class=\"thumbnail\"><div class=\"img-pic\"><a href=\"../".$pathprofilename."/".pathProName($related_rows['productName'])."-".$related_rows['ID'].".html\" target=\"_blank\" class=\"c-img-height\"><img alt='<translate>".$related_rows['productItemNo']."</translate>' title='<translate>".$related_rows['productItemNo']."</translate>' src=\"".$SmallFoldersProducts."/".$related_rows['productPic']."\" class=\"img-responsive\" /></a></div><div class=\"caption pro-name\"><h5><a href=\"../".$pathprofilename."/".pathProName($related_rows['productName'])."-".$related_rows['ID'].".html\" title='".$related_rows['productItemNo']."' ><translate>".$related_rows['productItemNo']."</translate></a></h5></div></div></div>";
			}
			//后10产品
			$related_sql2="select * from ls_products where productID = ".$products_rows['productID']." and ID < ".$products_rows['ID']." ORDER BY ID desc LIMIT 0 , ".$limitnum;
			$related_query2=$opendb->query($related_sql2);
			while($related_rows2=mysql_fetch_array($related_query2)){
				$related_products.="<div class=\"col-lg-4 col-md-4 col-sm-6 col-xs-12\"><div class=\"thumbnail\"><div class=\"img-pic\"><a href=\"../".$pathprofilename."/".pathProName($related_rows2['productName'])."-".$related_rows2['ID'].".html\" target=\"_blank\" class=\"c-img-height\"><img alt='<translate>".$related_rows['productItemNo']."</translate>' title='<translate>".$related_rows['productItemNo']."</translate>' src=\"".$SmallFoldersProducts."/".$related_rows2['productPic']."\" class=\"img-responsive\"  /></a></div><div class=\"caption pro-name\"><h5><a href=\"../".$pathprofilename."/".pathProName($related_rows2['productName'])."-".$related_rows2['ID'].".html\" title='<translate>".$related_rows2['productItemNo']."</translate>' ><translate>".$related_rows2['productItemNo']."</translate></a></h5></div></div></div>";
				
			}
			$related_products.="</div>";
			
			//相关产品 -- 前10产品与后10产品   --无图片
			$related_products_nopic = "";
			//前10个产品
			$related_sql_nopic="select * from ls_products where productID = ".$products_rows['productID']." and ID > ".$products_rows['ID']." ORDER BY ID asc LIMIT 0 , ".$related_products_num;
			$related_query_nopic=$opendb->query($related_sql_nopic);
			$related_products_nopic.="<h3>Related Products</h3>
			<ul class=\"related_nopic\">";
			while($related_rows_nopic=mysql_fetch_array($related_query_nopic)){
				$related_products_nopic.="<li><a href=\"".pathProName($related_rows_nopic['productName'])."-".$related_rows_nopic['ID'].".html\" target=\"_blank\">".$related_rows_nopic['productItemNo']."</a></li>";
			}
			//后10产品
			$related_sql2_nopic="select * from ls_products where productID = ".$products_rows['productID']." and ID < ".$products_rows['ID']." ORDER BY ID desc LIMIT 0 , ".$related_products_num;
			$related_query2_nopic=$opendb->query($related_sql2_nopic);
			while($related_rows2_nopic=mysql_fetch_array($related_query2_nopic)){
				$related_products_nopic.="<li><a href=\"".pathProName($related_rows2_nopic['productName'])."-".$related_rows2_nopic['ID'].".html\" target=\"_blank\">".$related_rows2_nopic['productItemNo']."</a></li>";
			}
			
			$related_products_nopic.="</ul>";
			
			
			//$ls_proshow="../".$BigFoldersProducts."/".$products_rows['productPic'];				 
			$ls_proshow=$BigFoldersProducts."/".$products_rows['productPic']."\" ";//大图
			$ls_proshow_id = $products_rows['ID'];
			$ls_proitemno=$products_rows['productItemNo'];							//编号
			$ls_proname=$products_rows['productName'];								//名字
			$ls_prodescription=htmlspecialchars_decode($products_rows['productSpecification'],ENT_QUOTES);	//规格
			$ls_prodescription=deployvideo($ls_prodescription);			
			/****************************编号、名称外的其他参数***********************************/
			
			$select_sql="select * from ls_functioncode ";
			$select_query=$opendb->query($select_sql);
			while ($select_rows = mysql_fetch_assoc($select_query)){
				switch($select_rows['codeID']){
					case "canshu":  //业务信息
						$canshu2_enable = $select_rows['enable'];
					break;
					case "basicInfo":  //基本信息
						$basicInfo2_enable = $select_rows['enable'];
					break;
					case "additionalInfo":  //附加信息
						$additionalInfo2_enable = $select_rows['enable'];
					break;
				}
			}
			
			$ls_morecontent = $products_rows['canshu'];  //产品业务信息
			if($ls_morecontent != "" && $canshu2_enable == 1){
				$morearray = explode('
', $ls_morecontent);
				$newarray = array();
				foreach($morearray as $moreval){
					$morearray2 = explode(':', $moreval);
					$newarray[] = $morearray2;
				}
				$ls_moreparamstr = "<table width=\"100%\" border=\"0\" style=\"line-height:20px; font-size:14px;\">";
				$num_i = 0;
				foreach($newarray as $newval){
					$ls_moreparamstr .= "<tr><td valign=\"top\"><span><b>".str_replace(" ", "&nbsp;", $newval[0])."</b></span>: </td><td>".$newval[1]."</td></tr>";
				}
				$ls_moreparamstr .= "</table>"; 
			}else {
				$ls_moreparamstr="";
			}
			
			$ls_basicInfo = $products_rows['basicInfo'];  //产品基本信息
			if($ls_basicInfo != "" && $basicInfo2_enable == 1){
				$morearray = explode('
', $ls_basicInfo);
				$newarray = array();
				foreach($morearray as $moreval){
					$morearray2 = explode(':', $moreval);
					$newarray[] = $morearray2;
				}
				$ls_moreBasicInfo = "<div class=\"panel panel-info\">
              <div class=\"panel-heading\">
                <h3 class=\"panel-title\">Basic Info</h3>
              </div>
              <div class=\"panel-body box_cont\">";
				$num_i = 0;
				foreach($newarray as $newval){
					$ls_moreBasicInfo .= "<p><span><b>".str_replace(" ", "&nbsp;", $newval[0])."</b></span>: ".$newval[1]."</p>";
				}
				$ls_moreBasicInfo .= "</div>
            </div>"; 
			}else {
				$ls_moreBasicInfo="";
			}
			
			$ls_additionalInfo = $products_rows['additionalInfo'];  //产品附加信息
			if($ls_additionalInfo != "" && $additionalInfo2_enable == 1){
				$morearray = explode('
', $ls_additionalInfo);
				$newarray = array();
				foreach($morearray as $moreval){
					$morearray2 = explode(':', $moreval);
					$newarray[] = $morearray2;
				}
				$ls_moreAdditionalInfo = "<div class=\"panel panel-info\">
              <div class=\"panel-heading\">
                <h3 class=\"panel-title\">Additional Info</h3>
              </div>
              <div class=\"panel-body box_cont\">";
				$num_i = 0;
				foreach($newarray as $newval){
					$ls_moreAdditionalInfo .= "<p><span><b>".str_replace(" ", "&nbsp;", $newval[0])."</b></span>: ".$newval[1]."</p>";
				}
				$ls_moreAdditionalInfo .= "</div>
            </div>"; 
			}else {
				$ls_moreAdditionalInfo="";
			}

			$ls_characteristics = $products_rows['characteristics'];
			$ls_advantages = $products_rows['advantages'];
			$ls_parameters = $products_rows['parameters'];

			/**********************************************************************************/
			//产品属性
			$select_sql2="select * from ls_prospec where productID = ".$products_rows['ID'];
			$select_query2=$opendb->query($select_sql2);
			$select_rows2=mysql_num_rows($select_query2); //总产品数
			if($select_rows2>0)
			{
				$ls_spec = "";
				while($prospec_row=mysql_fetch_assoc($select_query2))  //循环处理变量处理 变量名
				{	
					if(trim($prospec_row['specValue'])!=''){$ls_spec .= "".$prospec_row['specValue']."";}	
				}
				$ls_spec .= "";
				//echo $ls_spec;
				//die();
			}//产品属性
			//整合产品页面详细信息
			$ls_proitemno_nonintegrate=$ls_proitemno;
			$ls_proname_nonintegrate=$ls_proname;
			$ls_proitemno="<b>Item No.</b>: ".$ls_proitemno."<br />";
			$ls_proname="<b>Name</b>:".$ls_proname."<br />";
			$ls_prodescription_test=preg_replace("/<[\/|\w+]+?.*?\/?>/",null,$ls_prodescription);		//替换html标签到null
			$ls_prodescription_test=preg_replace("/$\w{2,7};/",null,$ls_prodescription_test);			//替换html转义字符
			$ls_prodescription_test=preg_replace("/\s*?/",null,$ls_prodescription_test);			//替换所有不可见的字符
			$ls_prodescription_test=trim($ls_prodescription_test);			//删除两端的空白字符
			
			if($ls_prodescription != null){
				$ls_prodescription=$ls_spec ."".($productDescriptionTitle==''?'':($productDescriptionTitle."")).$ls_prodescription;
			}else{
				$ls_prodescription="";
			}
			
			/*	if(strlen($ls_prodescription_test)!=0){
				$ls_prodescription=$ls_spec ."<b>".$productDescriptionTitle."</b>: ".$ls_prodescription;
			} else {
				$ls_prodescription=null;
			}
			*/
			
			$ls_foot=$foot;	

			//产品更多信息
			file_exists("widget/ls_moreinfo.php")?include "widget/ls_moreinfo.php":"";
			

// 深入一级目录，适应 productshow
			$ls_pronewsdongtai=str_replace('="../','="../../',$ls_newsdongtai);
			$ls_pronewsgonggao=str_replace('="../','="../../',$ls_newsgonggao);
			$ls_pronewstieshi=str_replace('="../','="../../',$ls_newstieshi);
			//底部信息
			
			//相关新闻
			file_exists("widget/ls_relative_news.php")?include "widget/ls_relative_news.php":"";

//组合数字导航
			if($j>$productBrowerNoOffset)
			{
				$startk=$j-$productBrowerNoOffset;
				$endk=$j+$productBrowerNoOffset;
			}
			else
			{
				$startk=1;
				$endk=$j+$productBrowerNoOffset;
			}
			if($endk>$mynum)
			{$endk=$mynum;}
			
			
			$k=1;									//产品大图数字导航下标
			$productBrowerStr='';					//产品大图数字导航页
			mysql_data_seek($result2, 0);
			while($products_rows_br=mysql_fetch_assoc($result2))
			{
				$productBrowerNo[$k]="<a href=\"".trim(str_replace(substr($products_rows_br['productPic'],-4),"",$products_rows_br['productPic'])).".html\" >".$k."</a>";		// get the array of no brower
				
				$k++;
			}
			
			for($ik=$startk;$ik<=$endk;$ik++)
			{
				if($ik==$j)
				{
					$productBrowerStr.="[".$productBrowerNo[$ik]."]";
				}
				else
				{
					$productBrowerStr.=$productBrowerNo[$ik];
				}
			}
			
			//echo $productBrowerStr;
			$ls_productBrowerStr=$productBrowerStr;
			//组合数字导航 end

			$code_sql="select * from ls_functioncode where enable=1 order by ID";	
			$opendb=new mydb();
			$code_query=$opendb->query($code_sql);
			while ($code_row=mysql_fetch_array($code_query)){
				switch($code_row['codeID']){
					case "statistics":
						if($code_row['enable']){
							$statistics = $code_row['code'];
						}
					break;
					case "onlines":
						if($code_row['enable']){
							$onlines = $code_row['code'];
						}
					break;
					case "maps":
						if($code_row['enable']){
							$maps = $code_row['code'];
						}
					break;
					case "share":
						if($code_row['enable']){
							$share = $code_row['code'];
						}
					break;
					case "indexKeywords":
						if($code_row['enable']){
							$indexKeywords = $code_row['code'];
						}
					break;
					case "onlinechart":
						if($code_row['enable']){
							$onlinechart = $code_row['code'];
						}
					break;
					case "shield":
						if($code_row['enable']){
							$shield = $code_row['code'];
						}
					break;
				}
			}
			
			$j++;
			$ls_prodescription = str_replace('../', $pathprofile, $ls_prodescription);
		
			$fp = fopen($proshow_path,"r");
			$procontent  = fread($fp,filesize ($proshow_path));
			$procontent  = str_replace("../","{ls_url}../",$procontent);
			$procontent  = str_replace("{ls_title}",$ls_protitle,$procontent);
			$procontent  = str_replace("{ls_keywords}",$ls_prokeywords,$procontent);
			$procontent  = str_replace("{ls_prodescription}",$ls_prodescription,$procontent);
			$procontent  = str_replace("{ls_url}",$ls_prourl,$procontent);
			$procontent  = str_replace("{ls_banner}",$ls_probanner,$procontent);
			$procontent  = str_replace("{ls_menu}",$ls_menu,$procontent);

			$procontent  = str_replace("{ls_statistics}",$statistics,$procontent);
			$procontent  = str_replace("{ls_onlines}",$onlines,$procontent);
			$procontent  = str_replace("{ls_maps}",$maps,$procontent);
			$procontent  = str_replace("{ls_share}",$share,$procontent);
			$procontent  = str_replace("{ls_onlinechart}",$onlinechart,$procontent);
			$procontent  = str_replace("{ls_shield}",$shield,$procontent);
			$procontent  = str_replace("{ls_productsKeywords}",$productsKeywords,$procontent);
			
			$procontent  = str_replace("{ls_canshu}",$ls_morecontent,$procontent);
			$procontent  = str_replace("{ls_characteristics}",$ls_characteristics,$procontent);
			$procontent  = str_replace("{ls_advantages}",$ls_advantages,$procontent);
			$procontent  = str_replace("{ls_parameters}",$ls_parameters,$procontent);
			$procontent = str_replace("{ls_cate}",$ls_cate,$procontent);
			$procontent  = str_replace("{ls_procate}",$ls_procate,$procontent);
			$procontent  = str_replace("{ls_s_cate}",$ls_s_cate,$procontent);
			$procontent  = str_replace("{ls_p_cate}",$ls_p_cate,$procontent);
			$procontent  = str_replace("{ls_languages}",$ls_languages,$procontent);
			$procontent  = str_replace("{ls_f_cate}",$ls_f_cate,$procontent);
			$procontent  = str_replace("{ls_indicatebar}",$ls_indicatebar,$procontent);
			$procontent  = str_replace("{ls_proshow}",$ls_proshow,$procontent);
			$procontent  = str_replace("{ls_proshow_width}",($showBigPicW==""?"530":$showBigPicW),$procontent);  //设置显示大图宽度则显示，否则 使用530 宽度
			$procontent  = str_replace("{ls_proitemno}",$ls_proitemno,$procontent);
			$procontent  = str_replace("{ls_proname}",$ls_proname,$procontent);
			$procontent  = str_replace("{ls_proitemno_nonintegrate}",$ls_proitemno_nonintegrate,$procontent);
			
			$procontent  = str_replace("{ls_proshow_id}",$ls_proshow_id,$procontent);
			
			$procontent  = str_replace("{ls_proname_nonintegrate}",$ls_proname_nonintegrate,$procontent);
			$procontent  = str_replace("{ls_description}",$ls_description,$procontent);
			$procontent  = str_replace("{ls_foot}",$ls_foot,$procontent);
			$procontent  = str_replace("{ls_procurrentpage}",$ls_procurrentpage,$procontent);
			$procontent  = str_replace("{ls_revo}",$lspro_revo,$procontent);
			$procontent  = str_replace("{ls_motif}",$s_m3_cate,$procontent);
			
			$procontent  = str_replace("{ls_relative_news}",$relative_new,$procontent);
			$procontent  = str_replace("{ls_current_id}",$products_rows['ID'],$procontent);
			$procontent  = str_replace("{ls_moreinfo}",$ls_moreinfo2,$procontent);
			$procontent  = str_replace("{ls_site_cate}",$site_cate,$procontent);
			$procontent  = str_replace("{ls_weiboshare}",$facebook_twitter_share,$procontent);
			$procontent  = str_replace("{ls_weibo}",$ls_facebook_twitter,$procontent);
		
			$procontent  = str_replace("{ls_copyright}",$row['copyright'],$procontent);
			$procontent  = str_replace("{relative_products_nopic}",$related_products_nopic,$procontent);
			$procontent  = str_replace("{relative_products_pic}",$related_products,$procontent);

			$procontent	= str_replace("{ls_newsdongtai}",$ls_pronewsdongtai,$procontent);
			$procontent	= str_replace("{ls_newsgonggao}",$ls_pronewsgonggao,$procontent);
			$procontent	= str_replace("{ls_newstieshi}",$ls_pronewstieshi,$procontent);

			$procontent	= str_replace("{ls_about}",$ls_about,$procontent);
			$procontent	= str_replace("{ls_news}",$ls_s_news,$procontent);
			$procontent	= str_replace("{ls_faq}",$ls_faq,$procontent);
			$procontent	= str_replace("{ls_classpro}",$ls_classpro,$procontent);
			$procontent	= str_replace("{ls_hotpro}",$ls_hotpro,$procontent);
			$procontent	= str_replace("{ls_designby}",$ls_designby,$procontent);
			$procontent	= str_replace("{ls_links}",$lspro_link,$procontent);
			$procontent	= str_replace("{ls_productBrowerStr}",$ls_productBrowerStr,$procontent);
			$procontent	= str_replace("{ls_left_contact}",$ls_left_contact,$procontent);
			$procontent = str_replace("{ls_addprolink}",$ls_addprolink,$procontent);	//指向主菜单中的Products链接
			$procontent = str_replace("{ls_addnewprolink}",$ls_addnewprolink,$procontent);	//指向主菜单中的NewProducts链接
			$procontent = str_replace("{ls_proitem_canshu}",$ls_moreparamstr,$procontent);//产品详细页中，业务信息。
			$procontent = str_replace("{ls_proitem_basicInfo}",$ls_moreBasicInfo,$procontent);//产品详细页中，基本信息。
			$procontent = str_replace("{ls_proitem_additionalInfo}",$ls_moreAdditionalInfo,$procontent);//产品详细页中，附加信息。
			$procontent = str_replace("{ls_revo}",$ls_revo,$procontent);//滚动图片。

			$procontent = circleNavigationLink2($products_rows['ID'],'B','{ls_previouslink}',$procontent, $pathprofilename);
			$procontent = circleNavigationLink2($products_rows['ID'],'F','{ls_nextlink}',$procontent, $pathprofilename);
			$procontent = str_replace("{ls_search}",ls_search("../../".$ls_prourl),$procontent); //搜索框
		
		$profilename="../".$profile;
		if($translate != ''){
		//翻译代码
		$folder_name = $translate;
		
		$r_name = deep_in_array($folder_name, $translate_name);
		
		$translateFile = "../".$r_name['folder_name'];
		createFolder($translateFile);
		$trans = "";
		$transFile = $profile;
		$trans = $proFiles.$showproductsFolders;
		createFolder($translateFile."/".$trans);
		$io = substr_count($proFiles, "/");
		$ipath = "";
		for($i=0; $i<$io; $i++){
			$ipath .= "../";
		}
		$replace = $proFiles;
		$procontent2 = str_replace($ls_proshow, "../".$ipath.$replace.$ls_proshow,$procontent);
		$procontent2 = str_replace("thumbnails/", "../".$ipath.$replace."/thumbnails/",$procontent2);
		$procontent2 = str_replace("src='images", "src='../".$ipath.$replace."/images/",$procontent2);  // 放大镜大图路径 翻译

		if( ifNeedTrans($translateFile."/".$transFile,$translate)||$_SESSION['transAll']==1){  //产品详细页，不存在和模拟翻译要生成，或者覆盖
		
			  if(translateApp($procontent2, $translateFile."/".$transFile, $r_name['translate_name'])){
				  echo "生成 <a href='".$translateFile."/".$transFile."'>".$translateFile."/".$transFile."</a>";
				  if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;
	  
				  echo "<br>";
	  
			  }else{
				  if($ls_debug) echo "".$translateFile."/".$transFile."失败！<br>";
			  }
		}
		else{
			echo "<a href='".$translateFile."/".$transFile."' target='_blank'>".$translateFile."/".$transFile."</a> 已存在， ".($_SESSION['transAll']==0?" 未生成。</br>":" ");
			}
	
	}else{
		if (is_file ($profilename)){ 
			@unlink ($profilename); //若文件已存在，则删除
		}
		//英文网站去除<translate>标签
		$translate_str = $procontent;
		$p = "%<translate>(.*?)</translate>%si";    //正则表达式
		preg_match_all($p, $procontent, $arr);
		$temarr = $arr[1];
		
		$source="en";
		$targets = $target;
	
		foreach($temarr as $val){
			$procontent = str_replace("<translate>".$val."</translate>", $val, $procontent);
		}
	 	$handle   = fopen($profilename,"w"); //打开文件指针，
		  /*
		　检查文件是否被创建且可写
		  */
		  if (!is_writable ($profilename))
			{ 
				if($ls_debug) 	 echo "文件：".$profilename."不可写，请检查其属性后重试！";
			  }
		  if (!fwrite ($handle,$procontent))
		  {  //将信息写入文件
				if($ls_debug)  echo "".$profilename."失败！";
		  } 
		  else
		  {
				echo "生成<a href='".$profilename."'>".$profilename."</a>";
				if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;

				echo "<br>";
		  }
		  fclose ($handle); //关闭指针
		}
					  //die ("创建<a href='".$filename."'>".$filename."</a>成功！<a href=\"temp.php?ls=normal\"><u>返回</u></a>");

		fclose ($fp);
		unset($ls_about,$ls_s_news,$ls_faq,$ls_left_contact,$related_products,$relative_new,$ls_description,$ls_proshow,$ls_prodescription,$procontent,$ls_revo,$ls_moreparamstr,$ls_productBrowerStr,$ls_prodescription,$ls_prokeywords,$ls_protitle);  //释放内存

	 } //end of while, end of one page
		$pro.="</div>";
		
		$ls_motif = $s_m2_cate;
		$index_path="../".$templates_var."/products.html";	
		writeIndexPages($index_path,$catetitle,$cateKeywords,$cateDescription,$url,$banner,$leftcate,$lspro_menu,
			$lsbrief,$procate,$procateid,$propage,$pro,$file,$echoname,$mynum,$allpages,$detail,$s_cate,$s_news,$s_p_cate,$ls_languages,$s_f_cate,$site_cate_pro,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf,$ls_facebook_twitter2,$translate);
//echo $pro;
		}	// end of for, all pages


		$opendb->close();
}

/*
------------------------------------------------------
参数：
$productID		当前页产品id
$direction		跳转方向(值:'F'下一条,'B'上一条)
$tag			替换标签
$content		需要处理的内容

返回值：替换完成的内容

程序功能：将指定标签替换成向前翻页以及向后翻页的链接

备注：仅支持本类中的页面跳转，不支持类间的。
------------------------------------------------------
*/

function circleNavigationLink($productID,$direction,$tag,$content){
	require('inc/constant.php');
	$opdb=new mydb();
	
	$lan = array();
	if($lang != "en"){
		$lan = $lang_cn;
	}else{
		$lan = $lang_en;
	}
	//Get product information
	$productInfoSql="select * from ls_products where ID={$productID}";
	$productInfoR=$opdb->query($productInfoSql);
	$productInfo=mysql_fetch_object($productInfoR);
	//Get Max and Min Num value
	$numLimitSql="select min(Num) as minNum, max(Num) as maxNum from ls_products where productID={$productInfo->productID}";
	$numLimitR=$opdb->query($numLimitSql);
	$numLimit=mysql_fetch_object($numLimitR);
	//According to $direction, search the next product
	if(($productInfo->Num==$numLimit->minNum)&&('B'==strtoupper($direction))){
		$linkProductNum=$numLimit->maxNum;
	}else if(($productInfo->Num==$numLimit->maxNum)&&('F'==strtoupper($direction))){
		$linkProductNum=$numLimit->minNum;
	}else{
		$searchCount=0;
		do{
			$searchCount++;
			$linkProductNum=('B'==strtoupper($direction))?($productInfo->Num-$searchCount):($productInfo->Num+$searchCount);
			$checkSql="select ID from ls_products where productID={$productInfo->productID} and Num={$linkProductNum}";
			$checkR=$opdb->query($checkSql);
		}while(0==mysql_num_rows($checkR));
	}
	//Get target product information and return the ready content
	$targetProductSql="select * from ls_products where productID={$productInfo->productID} and Num={$linkProductNum}";
	$targetProductR=$opdb->query($targetProductSql);
	$targetProduct=mysql_fetch_object($targetProductR);
	$targetProductFile=strrev(ltrim(stristr(strrev($targetProduct->productPic),'.'),'.')).'.html';
	$targetProductLink="<a href=\"{$targetProductFile}\">".(('B'==strtoupper($direction))?$lan['previous']:$lan['next'])."</a>";
	return str_replace($tag,$targetProductLink,$content);
}
/*
function circleNavigationLink2($productID,$direction,$tag,$content,$pathprofilename){
	require('inc/constant.php');
	$opdb=new mydb();
	$lan = array();
	if($lang != "en"){
		$lan = $lang_cn;
	}else{
		$lan = $lang_en;
	}
	//Get product information
	$productInfoSql="select * from ls_products where ID={$productID}";
	$productInfoR=$opdb->query($productInfoSql);
	$productInfo=mysql_fetch_object($productInfoR);
	//Get Max and Min Num value
	$numLimitSql="select min(Num) as minNum, max(Num) as maxNum from ls_products where productID={$productInfo->productID}";
	$numLimitR=$opdb->query($numLimitSql);
	$numLimit=mysql_fetch_object($numLimitR);
	//According to $direction, search the next product
	if(($productInfo->Num==$numLimit->minNum)&&('B'==strtoupper($direction))){
		$linkProductNum=$numLimit->maxNum;
	}else if(($productInfo->Num==$numLimit->maxNum)&&('F'==strtoupper($direction))){
		$linkProductNum=$numLimit->minNum;
	}else{
		$searchCount=0;
		do{
			$searchCount++;
			$linkProductNum=('B'==strtoupper($direction))?($productInfo->Num-$searchCount):($productInfo->Num+$searchCount);
			$checkSql="select ID from ls_products where productID={$productInfo->productID} and Num={$linkProductNum}";
			$checkR=$opdb->query($checkSql);
		}while(0==mysql_num_rows($checkR));
	}
	//Get target product information and return the ready content
	$targetProductSql="select * from ls_products where productID={$productInfo->productID} and Num={$linkProductNum}";
	$targetProductR=$opdb->query($targetProductSql);
	$targetProduct=mysql_fetch_object($targetProductR);
	$targetProductFile=pathProName($targetProduct->productName)."-".$targetProduct->ID.'.html';
	$targetProductLink="<a href=\"{$targetProductFile}\">".(('B'==strtoupper($direction))?$lan['previous']:$lan['next'])."</a>";
	return str_replace($tag,$targetProductLink,$content);
}*/
//产品详页  跳转方向(值:'F'下一条,'B'上一条)  首不接尾
function circleNavigationLink2($productID,$direction,$tag,$content,$pathprofilename){
	require('inc/constant.php');
	$opdb=new mydb();
	$lan = array();
	if($lang != "en"){
		$lan = $lang_cn;
	}else{
		$lan = $lang_en;
	}
	//Get product information
	$productInfoSql="select * from ls_products where ID={$productID}";
	$opdb = new mydb();
	$productInfoR=$opdb->query($productInfoSql);
	$productInfo=mysql_fetch_object($productInfoR);
	//Get Max and Min Num value
	$numLimitSql="select min(Num) as minNum, max(Num) as maxNum from ls_products where productID={$productInfo->productID}"; 
	$numLimitR=$opdb->query($numLimitSql);
	$numLimit=mysql_fetch_object($numLimitR);

	if(($productInfo->Num==$numLimit->minNum)&&('B'==strtoupper($direction))){
		$linkProductNum=$numLimit->maxNum;
	}else if(($productInfo->Num==$numLimit->maxNum)&&('F'==strtoupper($direction))){
		$linkProductNum=$numLimit->minNum;
	}else{
		$searchCount=0;
		do{
			$searchCount++;
			$linkProductNum=('B'==strtoupper($direction))?($productInfo->Num-$searchCount):($productInfo->Num+$searchCount);

			$checkSql="select * from ls_products where productID={$productInfo->productID} and Num={$linkProductNum}";
			$checkR=$opdb->query($checkSql);
			$targetProduct=mysql_fetch_object($checkR);
			if(mysql_num_rows($checkR) != 0){
				$targetProductFile=pathProName($targetProduct->productName)."-".$targetProduct->ID.'.html';
				$targetProductLink="<a href=\"{$targetProductFile}\">".(('B'==strtoupper($direction))?$lan['previous']:$lan['next'])."</a>";
			}
		}while(0==mysql_num_rows($checkR));
	}
	return str_replace($tag,$targetProductLink,$content);
}
/*
------------------------------------------------------
参数：
$leftcate
$leftcate
$pro
$file
$echoname

$indicatebar
程序功能：写入类下产品列表页index文件,相册页
------------------------------------------------------
*/
function writeIndexPages($index_path,$catetitle,$cateKeywords,$cateDescription,$url,$banner,$leftcate,$lspro_menu,$lsbrief,$procate,$procateid,$propage,$pro,$file,$echoname,$mynum,$allpages,&$detail,$s_cate,$s_news,$s_p_cate,$ls_languages,$s_f_cate,$site_cate_pro,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf,$ls_facebook_twitter2,$translate){
	global $ls_procurrentpage,$menuListscateid,$ls_about,$ls_news,$ls_classpro,$ls_hotpro,$ls_link,$ls_designby,$ls_news,$ls_faq,$ls_newsdongtai,$ls_newsgonggao,$ls_newstieshi,$ls_addprolink,$ls_addnewprolink,$ls_moreparam,$facebook_twitter_share,$facebook_twitter;
	
	$needleonmouseover="<ul id=\"menuLists".$menuListscateid."\" style=\"display:none;\">\n";	//替换悬停菜单内容
	$replaceonmouseover="<ul id=\"menuLists".$menuListscateid."\" style=\"display:block;\">\n";

	if($menuListscateid!=0){$s_cate=str_replace($needleonmouseover,$replaceonmouseover,$s_cate);}
	//if($menuListscateid!=0){$s_p_cate=str_replace($needleonmouseover,$replaceonmouseover,$s_p_cate);}
	
	//echo $menuListscateid."-pp";
	
	if(!file_exists($index_path)){
		if($ls_debug) echo "模板文件".$index_path."不存在！请设计好模板后重新生成。</br></br>";
		return;
	}
	
	$code_sql="select * from ls_functioncode where enable=1 order by ID";	
	$opendb=new mydb();
	$code_query=$opendb->query($code_sql);
	while ($code_row=mysql_fetch_array($code_query)){
		switch($code_row['codeID']){
			case "statistics":
				if($code_row['enable']){
					$statistics = $code_row['code'];
				}
			break;
			case "onlines":
				if($code_row['enable']){
					$onlines = $code_row['code'];
				}
			break;
			case "maps":
				if($code_row['enable']){
					$maps = $code_row['code'];
				}
			break;
			case "share":
				if($code_row['enable']){
					$share = $code_row['code'];
				}
			break;
			case "indexKeywords":
				if($code_row['enable']){
					$indexKeywords = $code_row['code'];
				}
			break;
			case "onlinechart":
				if($code_row['enable']){
					$onlinechart = $code_row['code'];
				}
			break;
			case "shield":
				if($code_row['enable']){
					$shield = $code_row['code'];
				}
			break;
		}
	}
	
	$ls_facebook_twitter = $ls_facebook_twitter2;

	//产品模板地址
	$ls_lineno=__LINE__.(__FUNCTION__==""?"":" 函数:". __FUNCTION__).(__CLASS__==""?"":" 类:".__CLASS__) ;
	$ls_title=$catetitle;//===================================网站标题
	$ls_keywords=$cateKeywords;	//============================网站关键字
	$ls_description=$cateDescription;//=======================网站描述
	$ls_url=$url;
	$ls_banner=$banner;//=====================================大类主体图
	$ls_cate=$leftcate;	

	$ls_s_cate=$s_cate;//=====================================左侧产品类别
	$ls_s_news=$s_news;
	$ls_p_cate=$s_p_cate;//=====================================左侧产品类别
	$ls_f_cate=$s_f_cate;
	$ls_menu=$lspro_menu;//主菜单
	$ls_indicatebar=$indicatebar;
	if($lsbrief!=""){
		$ls_brief="<div id=\"brief\">".$lsbrief."</div>";
	}
	$ls_procate=$procate;//===================================产品类别
	$ls_procateid=$procateid;//===============================产品类别ID
	$ls_propage=$propage;//===================================产品分页数字
	$ls_pro=$pro;//===========================================产品信息
	$ls_pro = str_replace("{ls_url}",$ls_url,$pro);
	$ls_foot=$foot;//=========================================底部信息
	$fp	= fopen($index_path,"r");//===========================打开产品详细页模版
	$content = fread($fp,filesize ($index_path));//===========读取产品详细页模版所有内容
	$content = str_replace("{ls_title}",$ls_title,$content);
	$content = str_replace("../","{ls_url}../",$content);
	$content = str_replace("{ls_keywords}",$ls_keywords,$content);
	$content = str_replace("{ls_url}",$ls_url,$content);
	$content = str_replace("{ls_banner}",$ls_banner,$content);
	$content = str_replace("{ls_menu}",$ls_menu,$content);
	$content = str_replace("{ls_cate}",$ls_cate,$content);
	$content = str_replace("{ls_s_cate}",$ls_s_cate,$content);
	$content = str_replace("{ls_p_cate}",$ls_p_cate,$content);
	$content = str_replace("{ls_languages}",$ls_languages,$content);
	$content = str_replace("{ls_f_cate}",$ls_f_cate,$content);
	$content = str_replace("{ls_motif}",$ls_motif,$content);
	
	require('constant.php');
	
	$content = str_replace("{ls_statistics}",$statistics,$content);
	$content = str_replace("{ls_onlines}",$onlines,$content);
	$content = str_replace("{ls_maps}",$maps,$content);
	$content = str_replace("{ls_share}",$share,$content);
	$content = str_replace("{ls_onlinechart}",$onlinechart,$content);
	$content = str_replace("{ls_shield}",$shield,$content);
	$content = str_replace("{ls_productsKeywords}",$productsKeywords,$content);
	
	$content = str_replace("{ls_site_cate}",$site_cate_pro,$content);
	$content = str_replace("{ls_weiboshare}",$facebook_twitter_share,$content);
	$content = str_replace("{ls_weibo}",$ls_facebook_twitter2,$content);
	
	$content = str_replace("{ls_foot}",$ls_foot,$content);
	$content = str_replace("{ls_procate}",$ls_procate,$content);
	$content = str_replace("{ls_brief}",$ls_brief,$content);
	$content = str_replace("{ls_detail}",$detail,$content);
	$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
	$content = str_replace("{ls_behalf}",$behalf,$content);
	$content = str_replace("{ls_description}",$ls_description,$content);
	$content = str_replace("{ls_procateid}",$ls_procateid,$content);
	$content = str_replace("{ls_propage}",$ls_propage,$content);
	$content = str_replace("{ls_pro}",$ls_pro,$content);
	$content = str_replace("{ls_procurrentpage}",$ls_procurrentpage,$content);
	$content = str_replace("{ls_about}",$ls_about,$content);
	$content = str_replace("{ls_news}",$ls_s_news,$content);
	$content = str_replace("{ls_faq}",$ls_faq,$content);
	$content = str_replace("{ls_newsdongtai}",$ls_newsdongtai,$content);
	$content = str_replace("{ls_newsgonggao}",$ls_newsgonggao,$content);
	$content = str_replace("{ls_newstieshi}",$ls_newstieshi,$content);
	$content = str_replace("{ls_classpro}",$ls_classpro,$content);
	$content = str_replace("{ls_hotpro}",$ls_hotpro,$content); 
	$content = str_replace("{ls_designby}",$ls_designby,$content);
	$content = str_replace("{ls_links}",$ls_link,$content);
	$content = str_replace("{ls_addprolink}",$ls_addprolink,$content);	//指向主菜单中的Products链接
	$content = str_replace("{ls_addnewprolink}",$ls_addnewprolink,$content);	//指向主菜单中的NewProducts链接
	$content = str_replace("{ls_revo}",$ls_revo,$content);	//指向主菜单中的NewProducts链接
	$content = str_replace("{ls_search}",ls_search("../".$ls_url),$content); //搜索框
	$tem_sql="select * from ls_config order by ID";	
	$tem_query=$opendb->query($tem_sql);
	$row=mysql_fetch_array($tem_query);
	$content = str_replace("{ls_copyright}",$row['copyright'],$content);
	$filename="../".$file;
	if($translate != ''){
		//翻译代码
		$folder_name = $translate;
		
		$r_name = deep_in_array($folder_name, $translate_name);
		
		$translateFile = "../".$r_name['folder_name'];
		createFolder($translateFile);
		$trans = "";
		$transFile = str_replace("../", "", $filename);
		$trWords = explode("/", $transFile);
		for($i = 0; $i < (count($trWords)-1); $i++){
			$trans .="/".$trWords[$i];
		}
		createFolder($translateFile.$trans);
		$content2 = str_replace("<img src=\"", "<img src=\"..".$trans."/",$content);
		
		if($proGallaryPageWr||ifNeedTrans($translateFile."/".$transFile,$translate,true)||$_SESSION['transAll']==1){  //相册页翻译，不存在和模拟翻译要生成，或者覆盖

			  if(translateApp($content2, $translateFile."/".$transFile, $r_name['translate_name'])){
				  echo "生成 <a href='".$translateFile."/".$transFile."'>".$translateFile."/".$transFile."</a>";
				  if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;
	  
				  echo "<br>";
			  }else{
				  if($ls_debug) echo "生成文件".$translateFile."/".$transFile."失败！<br>";
			  }
		}
		else
		{echo "<a href='".$translateFile."/".$transFile."' target='_blank'>".$translateFile."/".$transFile."</a> 已存在， ".($_SESSION['transAll']==0?" 未生成。</br>":" ");}	  
	}else{
		if (is_file($filename)){
			//若文件已存在，则删除
			@unlink($filename); 
		}
		//英文网站去除<translate>标签
		$translate_str = $content;
		$p = "%<translate>(.*?)</translate>%si";    //正则表达式
		preg_match_all($p, $content, $arr);
		$temarr = $arr[1];
		
		$source="en";
		$targets = $target;
	
		foreach($temarr as $val){
			$content = str_replace("<translate>".$val."</translate>", $val, $content);
		}
		$handle = fopen($filename,"w"); //打开文件指针，
		/*
		　检查文件是否被创建且可写
		*/
		if(!is_writable($filename)){ 
			if($ls_debug) echo "文件：".$filename."不可写，请检查其属性后重试！";
		}
		if(!fwrite($handle,$content)){
			//将信息写入文件
			if($ls_debug) echo "生成文件".$filename."失败！";
		}else{
			echo "生成<a href='".$filename."'>".$filename."</a>";
			if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;

			echo "<br>";
		}
		
		fclose($handle);//关闭文件指针
	}
	fclose($fp);	//关闭文件指针
	
	if($index_path=="../".$templates_var."/catedetail.html"){
		echo $echoname." 详细页面成功。";
		if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;

			echo "<br><br>";


	}else{
		echo $echoname."共有".$mynum."个产品。总共生成".$allpages."类别页。"; 
		if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;

		echo "<br><br>";
	}
}
/*
------------------------------------------------------
参数：
$index_path  //模板地址
$filename  //生成文件名
$mainpart  //主体内容
$mainpartsubject  //switch生成文件指针
globle:
	$ls_about			//首页About us
	$ls_news			//首页News
	$ls_classpro			//Class products
	$ls_hotpro			//首页 Hot products

程序功能：二级页（列表页）index,aboutus,contacuts,news,download
,rd,certificate,workshop,feedback,packing,quality
------------------------------------------------------
*/

function writeMainMenuItemFile($index_path,$ls_title,$ls_keywords,$ls_description,$ls_cate,$ls_motif,$ls_menu,$ls_foot,
$filename,$mainpart,$ls_introduction,$mainpartsubject,$ls_feedbackemail,$ls_propage,$s_cate,$s_p_cate,$ls_languages,$ls_addprolink,$ls_addnewprolink,$newstag,$translate,$contact_array=''){
	require_once('conn.php');
	global $contact_array;

	if(!file_exists($index_path)){
		echo "模板文件".$index_path."不存在！请设计好模板后重新生成。</br></br>";
		return;
	}
	global $ls,$subFolder,$ls_m_news;
	global $ls_about,$ls_news,$ls_faq,$ls_homepro,$ls_newpro,$ls_classpro,$ls_hotpro,$ls_designby,$ls_link,$ls_newsdongtai,$ls_newsgonggao,$ls_newstieshi,	$ls_revo,$ls_allcatepics,$site_cate1,$p_m_cate,$p_m_cate1,$p_m_cate2,$p_m_cate3,$facebook_twitter,$facebook_twitter_share,$ls_h1_news;	//首页About us, 首页News, 首页 Hot products

	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	
	$tem_sql="select * from ls_config order by ID";	
	$tem_query=$opendb->query($tem_sql);
	$row=mysql_fetch_array($tem_query);
	$templates_var = $row['templates'];
	$tel = $row['tel'];
	$copyright=$row['copyright'];
	$code_sql="select * from ls_functioncode where enable=1 order by ID";	
	$code_query=$opendb->query($code_sql);
	while ($code_row=mysql_fetch_array($code_query)){
		switch($code_row['codeID']){
			case "statistics":
				if($code_row['enable']){
					$statistics = $code_row['code'];
				}
			break;
			case "onlines":
				if($code_row['enable']){
					$onlines = $code_row['code'];
				}
			break;
			case "maps":
				if($code_row['enable']){
					$maps = $code_row['code'];
				}
			break;
			case "share":
				if($code_row['enable']){
					$share = $code_row['code'];
				}
			break;
			case "indexKeywords":
				if($code_row['enable']){
					$indexKeywords = $code_row['code'];
				}
			break;
			case "onlinechart":
				if($code_row['enable']){
					$onlinechart = $code_row['code'];
				}
			break;
			case "shield":
				if($code_row['enable']){
					$shield = $code_row['code'];
				}
			break;
		}
	}
	
	$facebook_twitter = str_replace("YOUR-FACEBOOK",$row['facebook'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-TWITTER",$row['twitter'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-LINKEDIN",$row['linkedin'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-GOOGLE",$row['google'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-PINTEREST",$row['pinterest'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-YOUTUBE",$row['youtube'],$facebook_twitter);
	
	$ls_facebook_twitter = str_replace("../","",$facebook_twitter);//cate
	$ls_facebook_twitter_m =$facebook_twitter;
	
	if($lang != "en"){
		$lan = $lang_cn;
	}else{
		$lan = $lang_en;
	}
	
	$mobi_tem_sql="select * from ls_mobiconfig order by ID";	
	$mobi_tem_query=$opendb->query($mobi_tem_sql);
	$mobi_row=mysql_fetch_array($mobi_tem_query);
	$mobi_logo = $mobi_row['logo'];
	$mobi_companyName = $mobi_row['companyName'];
	$mobi_siteKeywords = $mobi_row['siteKeywords'];
	$mobi_siteDescription = $mobi_row['siteDescription'];
	$ls_m_logo = "<img src='images/".$mobi_logo."' />";
	//echo $templates_var;

	$menu_sql="select * from ls_menu where argument='".$mainpartsubject."' ";
	$menu_query=$opendb->query($menu_sql);
	$menu_row=mysql_fetch_assoc($menu_query);
	//echo $ls."kk".$menu_row['enable'];
	if($menu_row['enable']==0&&$menu_row['argument']==$mainpartsubject){
		// 如果主菜单项没有启动则退出函数 
		return;
	}
	
	//首页友情链接  start
	$links_sql = "select * from ls_links where enable = 1 and cateName != 'Blog'";
	$links_query = $opendb->query($links_sql);
	while($links_rows=mysql_fetch_assoc($links_query)){
		$links_str .= "<li><a href ='".$links_rows['linkURL']."' target='_blank'>".$links_rows['linkTitle']."</a></li>";
	}
	$ls_links = $links_str;
	//首页友情链接  end
	
	//首页视频  start {ls_video}
	$video_sql = "select * from ls_video where enable = 1 and videoBool = 1 limit 0,2";
	$video_query = $opendb->query($video_sql);
	if("192.168.2.20"==$_SERVER["SERVER_ADDR"] || "pmf.lanscend.cn" == $_SERVER['SERVER_NAME']){
		$url=explode("/", $_SERVER["REQUEST_URI"]);
		$path = "/".$url[1];
	}else{
		$url="";
	}
	$i = 0;
	//$video_str = "<ul class=\"p_list\">";
	while($news_rows=mysql_fetch_assoc($video_query)){
		$i++;
		if($news_rows['code']==NULL){
			$video_str .= "<div id='tab".$i."'><b>".$news_rows['videoName']."</b><br /><embed src='".$path."/video/".$news_rows['videoFile']."' type='application/x-shockwave-flash' width='".$news_rows['videoW']."' height='".$news_rows['videoH']."' quality='high' /></div>";
		}else{
			$video_str .= "<div id='tab".$i."'><b>".$news_rows['videoName']."</b><br />".$news_rows['code']."<br />".$news_rows['videoName']."</div>";
		}
	}
	//$video_str .= "</ul>";
	$ls_video = $video_str;
	//首页视频  end
	
	$fp = fopen($index_path,"r");
	$ls_s_cate = $s_cate;				//左侧产品类别
	$ls_p_cate = $s_p_cate;				//左侧产品类别
	$ls_languages = $ls_languages;        //语言国旗
	$ls_motif = $ls_motif;
	$content = fread($fp,filesize ($index_path));
	$content = str_replace("href=\"../m/","href=\"",$content);
	$content = str_replace("src=\"../m/","src=\"",$content);
	//$content = str_replace("href=\"css/","href=\"Templates/css/",$content);
	//$content = str_replace("src=\"images/","src=\"Templates/images/",$content);
	
	if($mainpartsubject != 'blog'){
		if($subFolder){
			//如果在子目录里面有"../../"则换成"../"
			$content = str_replace("../../","../",$content);}
		else{
			//用来预防根目录下有其他语言版本
			$content = str_replace("../.","../x",$content);
			$content = str_replace("../","",$content);
			$content = str_replace("x./","../",$content);
		}
	}else{
		$content = str_replace("{ls_news}",$ls_h1_news,$content);
		$ls_facebook_twitter = $facebook_twitter;
	}
	
	$content = str_replace("template=\"/Templates/all.dwt\"","",$content);	//清除模板地址
	$content = str_replace("{ls_title}",$ls_title,$content);
	$content = str_replace("{ls_keywords}",$ls_keywords,$content);
	$content = str_replace("{ls_description}",$ls_description,$content);
	$content = str_replace("{ls_menu}",$ls_menu,$content);
	$content = str_replace("{ls_s_cate}",$ls_s_cate,$content);
	$content = str_replace("{ls_p_cate}",$ls_p_cate,$content);
	$content = str_replace("{ls_f_cate}",get_pro_cate(0),$content);
	$content = str_replace("{ls_motif}",$ls_motif,$content);
	$content = str_replace("{ls_m_news}",$ls_m_news,$content);
	$content = str_replace("{ls_m_tel}",$tel,$content);
	$content = str_replace("{ls_about}",$ls_about,$content);
		
	//首页新闻列表  {ls_news}, {ls_news_dongtai}, {ls_news_gonggao}, {ls_news_tieshi}
	$news_cate_sql3="select * from `ls_functioncates` where functionName='新闻分类' and enable=1 order by Num asc ";
	$news_cate_query3=$opendb->query($news_cate_sql3);
	$i=0;
	while($news_cate_rows3=mysql_fetch_assoc($news_cate_query3)){
		$sort='';
		if($newsSort=="ID"){
			$sort = "ID";
		}else if($newsSort=="Num"){
			$sort = "Num";
		}else{
			$sort = "ID";
		}
		//equire_once('inc/char_set.php');
	
		$news = "";
		$nui = 0;
		
		$news_sql="select * from ls_news where cate = '".$news_cate_rows3['cateName']."' and enable=1 order by $sort desc limit 0, ".$newsNum;
		$news_query=$opendb->query($news_sql);
		$news = "";
		while($news_rows=mysql_fetch_assoc($news_query)){
			$suffix_str2 = $news_cate_rows3['suffStr'];
			
			$news.="<div class=\"col-lg-6 col-md-6 col-sm-12 col-xs-12\">
				<div class=\"row home-news\">
					<div class=\"col-lg-3 col-md-3 col-sm-3 col-xs-12\">
                           <div class=\"date\"><span>20".date('y', strtotime($news_rows['newsDate']))."
<br /><div style=\"font-size:39px;\">".date('m', strtotime($news_rows['newsDate']))."</div></span></div>
									
								  </div>
								  <div class=\"col-lg-9 col-md-9 col-sm-9 col-xs-12\">
									<ul class=\"list-unstyled news-list\">
									<li><a href=\"".$newsshowFolders."/news".$suffix_str2.$news_rows['ID'].".html\"><translate>".$news_rows['newsTitle']."</translate></a>
									</li>
                                    
                                    </ul>
									<p><translate>".mb_substr(strip_tags($news_rows['newsText']),0,100,'utf-8')."</translate> ...</p>
					</div>
				</div>
       </div>";
		}

			







		$ls_news = $news;
		$content = str_replace("{ls_news".$news_cate_rows3['suffStr']."}",$ls_news,$content);
		$i++;
	}
	//首页新闻列表 End
	
	$content = str_replace("{ls_statistics}",$statistics,$content); //统计代码
	$content = str_replace("{ls_onlines}",$onlines,$content);  //在线联系(QQ)
	$content = str_replace("{ls_maps}",$maps,$content);  //地图代码
	$content = str_replace("{ls_share}",$share,$content);  //分享代码
	$content = str_replace("{ls_onlinechart}",$onlinechart,$content);  //在线联系
	$content = str_replace("{ls_shield}",$shield,$content);  //首页屏蔽
	
	$content = str_replace("{ls_site_cate}",$site_cate1,$content);
	$content = str_replace("{ls_weiboshare}",$facebook_twitter_share,$content);
	$content = str_replace("{ls_faq}",$ls_faq,$content);
	$content = str_replace("{ls_newsdongtai}",$ls_newsdongtai,$content);
	$content = str_replace("{ls_newsgonggao}",$ls_newsgonggao,$content);
	$content = str_replace("{ls_newstieshi}",$ls_newstieshi,$content);
	$content = str_replace("{ls_homepro}",$ls_homepro,$content);
	$content = str_replace("{ls_languages}",$ls_languages,$content);
	$content = str_replace("{ls_designby}",$ls_designby,$content);
	$content = str_replace("{ls_cate}",$ls_cate,$content);
	$content = str_replace("{ls_foot}",$ls_foot,$content);
	
	$content = str_replace("{ls_copyright}",$copyright,$content);
	$content = str_replace("{ls_addprolink}",$ls_addprolink,$content);	//指向主菜单中的Products链接
	$content = str_replace("{ls_addnewprolink}",$ls_addnewprolink,$content);	//指向主菜单中的NewProducts链接
	$content = str_replace("{ls_classpro}",$ls_classpro,$content); //类别产品链接
	$content = str_replace("{ls_hotpro}",$ls_hotpro,$content); //热点产品链接
	$content = str_replace("{ls_revo}",$ls_revo,$content); //主题流动图片
	$content = str_replace("{ls_search}",ls_search(),$content); //搜索框
	$content = str_replace("{ls_allcatepics}",$ls_allcatepics,$content); //搜索框
	
	$content = str_replace("{ls_m_logo}",$ls_m_logo,$content); //logo
	$content = str_replace("{ls_m_title}",$mobi_companyName,$content); //手机网页标题
	$content = str_replace("{ls_m_keywords}",$mobi_siteKeywords,$content);
	$content = str_replace("{ls_m_description}",$mobi_siteDescription,$content);
	
	$content = str_replace("{ls_m_cate}",$p_m_cate,$content); //手机产品分类
	
	//首页二维码程序  start
	if($mainpartsubject=='index'){
			if(file_exists('code/png/2.png')){
				$code = '
						<script type="text/javascript">
							$(function(){
							$(window).scroll(function(){
							var scrollTop = document.body.scrollTop || document.documentElement.scrollTop || 0;
							$(".christmas_ad").stop();
							var scrollTop2 = (scrollTop+160) - $(".christmas_ad").position().top;
							$(".christmas_ad:not(:animated)").animate({top:"+="+scrollTop2+"px"},100);
							})
							}) 
							</script>
							<div class="christmas_ad" style="width:155px; height:220px; position:absolute; top:250px; right:0px;">
								<a href="javascript:void(0)" ><img src="ls_admin/code/png/2.png" style="border 1px red" /></a>
							</div>
							</body>
						';
			}else{
				$code = "</body>";
				}
		}
	//首页二维码程   end


	switch($mainpartsubject){
		case "index":
		
		$inf_sql="select * from ls_information where inMenu = 'notice' order by ID";
		$inf_query=$opendb->query($inf_sql);
		$inf_row=mysql_fetch_array($inf_query);
		
		$content = str_replace("{ls_allabout}",$mainpart,$content);
		$content = str_replace("{ls_notice}",$inf_row['content'],$content);
		$content = str_replace("{ls_video}",$ls_video,$content);
		$content = str_replace("{ls_indexKeywords}",$indexKeywords,$content);
		
		//首页工厂展示 Start {ls_workshop}
		$products_sql="select * from ls_workshop where enable=1 ";
		$products_sql.=" order by Num asc ";
		$products_query=$opendb->query($products_sql);
		$homework="";
		$i = 0;
		while($news_rows=mysql_fetch_assoc($products_query)){
			$homework.="<div class=\"col-lg-3 col-md-3 col-sm-6 col-xs-12\">
				<div ><a href=\"".$WorkShopFolders."/workshop-page".$news_rows['ID'].".html\"><img src=\"".$WorkShopFolders."/images/".$news_rows['workshopPic']."\" class=\"img-thumbnail img-responsive\" title='".$news_rows['workshopTitle']."' alt='".$news_rows['workshopTitle']."' /></a><div class=\"caption pro-name\"><a href=\"".$WorkShopFolders."/workshop-page".$news_rows['ID'].".html\"><translate>".$news_rows['workshopTitle']."</translate></a></div></div>
			  </div>";
			$count++;
			$i++;
		}
		//首页工厂展示 End

		//首页证书展示 Start
		$products_sql="select * from ls_certificate where enable=1 ";
		$products_sql.=" order by Num asc ";
		$products_query=$opendb->query($products_sql);
		$homecer="";
		$i = 0;
		while($news_rows=mysql_fetch_assoc($products_query)){
			$homecer.="<div class=\"col-lg-3 col-md-3 col-sm-6 col-xs-12\">
				<div ><a href=\"".$CertificateFolders."/certificate-page".$news_rows['ID'].".html\"><img src=\"certificate/images/".$news_rows['Pic']."\" class=\"img-thumbnail img-responsive\" title='".$news_rows['Title']."' alt='".$news_rows['Title']."' /></a><div class=\"caption pro-name\"><a href=\"".$CertificateFolders."/certificate-page".$news_rows['ID'].".html\"><translate>".$news_rows['Title']."</translate></a></div></div>
			  </div>";
			$count++;
			$i++;
		}
		//首页证书展示 End
		
		//首页包装展示 Start
		$products_sql="select * from ls_packing where enable=1 ";
		$products_sql.=" order by Num asc ";
		$products_query=$opendb->query($products_sql);
		$homepack="";
		$animation = array("bounceInLeft", "bounceInUp", "bounceInUp", "bounceInRight");
		$count2=0.4;
		$i = 0;
		while($news_rows=mysql_fetch_assoc($products_query)){
			$count2 = $count2 + 0.2;
			$homepack.="<div class=\"col-lg-3 col-md-3 col-sm-6 col-xs-12 home-packing\">
				<div data-wow-delay=\"".$count2."s\" class=\"span3 wow ".$animation[$i]." center\"><a href=\"".$packingFolders."/packing-page".$news_rows['ID'].".html\"><img src=\"".$packingFolders."/images/".$news_rows['Pic']."\" class=\"img-thumbnail img-responsive\" title='".$news_rows['Title']."' alt='".$news_rows['Title']."' /></a><div class=\"caption pro-name\"> <a href=\"".$packingFolders."/packing-page".$news_rows['ID'].".html\"><translate>".$news_rows['Title']."</translate></a></div></div>
			  </div>";
			$count++;
			$i++;
		}
		//首页包装展示 End

		$content = str_replace("{contact_tel}",$contact_array['contact_tel'],$content);
		$content = str_replace("{contact_email}",$contact_array['contact_email'],$content);
		$content = str_replace("{contact_qq}",$contact_array['contact_qq'],$content);
		$content = str_replace("{contact_fax}",$contact_array['contact_fax'],$content);
		$content = str_replace("{contact_skype}",$contact_array['contact_skype'],$content);
		$content = str_replace("{contact_http}",$contact_array['contact_http'],$content);
		$content = str_replace("{contact_name}",$contact_array['contact_name'],$content);
		$content = str_replace("{contact_address}",$contact_array['contact_address'],$content);
		$content = str_replace("{contact_companyname}",$contact_array['contact_companyname'],$content);
		
		$content = str_replace("{ls_workshop}",$homework,$content);
		$content = str_replace("{ls_certificate}",$homecer,$content);
		$content = str_replace("{ls_packing}",$homepack,$content);
		
		$content = str_replace("</body>",$code,$content);
		break;
		case "aboutus":
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\"><translate>".$lan['about']."</translate></li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		
		$content = str_replace("{ls_allabout}","<translate>".$mainpart."</translate>",$content);
		break;
		case "feedback": 
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['feedback']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_feedbackemail}",$ls_feedbackemail,$content);
		$content = str_replace("{ls_feedback}",$mainpart,$content);
		break;
		case "contactus":
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['contact']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_contact}",$mainpart,$content);
		
		$content = str_replace("{contact_tel}",$contact_array['contact_tel'],$content);
		$content = str_replace("{contact_email}",$contact_array['contact_email'],$content);
		$content = str_replace("{contact_qq}",$contact_array['contact_qq'],$content);
		$content = str_replace("{contact_fax}",$contact_array['contact_fax'],$content);
		$content = str_replace("{contact_skype}",$contact_array['contact_skype'],$content);
		$content = str_replace("{contact_http}",$contact_array['contact_http'],$content);
		$content = str_replace("{contact_name}",$contact_array['contact_name'],$content);
		$content = str_replace("{contact_address}",$contact_array['contact_address'],$content);
		$content = str_replace("{contact_companyname}",$contact_array['contact_companyname'],$content);
		
		break;
		
		// 新闻列表页，核心内容
		case "news":
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\" style='text-transform : capitalize;'>".$lan['news']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_newslist}",$mainpart,$content);
		$content = str_replace("{newstag}",$newstag,$content);
		break;
		case "blog":
		$ls_links = $ls_foot;
		$ls_indicatebar = "<li><a href=\"../index.html\">".$lan['home']."</a></li>
                           <li class=\"active\" style='text-transform : capitalize;'>".$lan['blog']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_blogtag}",$newstag,$content);
		$content = str_replace("{ls_links}",$ls_links,$content);
		
		$linksblog_sql = "select * from ls_links where enable = 1 and cateName = 'Blog'";
		$linksblog_query = $opendb->query($linksblog_sql);
		while($linksblog_rows=mysql_fetch_assoc($linksblog_query)){
			$linksblog_str .= "<li><a href ='".$linkblogs_rows['linkURL']."' target='_blank'>".$linksblog_rows['linkTitle']."</a></li>";
		}
		$ls_linkblog = $linksblog_str;
		$content = str_replace("{ls_linkblog}",$ls_linkblog,$content);
		
		$content = preg_replace("%<ls_blogcate>(.*?)</ls_blogcate>%si", get_blog_cate($index_path), $content);
		$content = preg_replace("%<ls_foreach>(.*?)</ls_foreach>%si", $mainpart, $content);
		//$content = str_replace("{ls_newslist}",$mainpart,$content);
		$content = str_replace("{newstag}",$newstag,$content);
		break;
		case "faq":
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['faq']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_newslist}",$mainpart,$content);
		$content = str_replace("{newstag}",$newstag,$content);
		break;
		case "prolist.html":
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['products']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_classpro}",$ls_classpro,$content);
		break;
		
		case "download": //生成下载
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['download']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_downlist}",$mainpart,$content);
		break;
		
		case "management": //生成管理团队(Management)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);

		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['management']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "workshop": //生成车间图片(Workshop)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['workshop']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "video": //生成车间图片(Workshop)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['video']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "qualitycontrol": //生成质量控制图片qualitycontrol)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['quality']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "rd": //生成研发(R&D)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['rd']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "certificate": //生成证书(Certificate)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['certificate']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "packing": //生成包装(Packing)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['packing']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "brand": //生成品牌(Brand)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['brand']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "history": //生成品牌(history)
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['history']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = preg_replace("%<ls_foreach>(.*?)</ls_foreach>%si", $mainpart, $content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "hotpro.html":  //生成热点产品页
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['hotpro']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_hotpro}",$ls_hotpro,$content);
		break;
		
		case "newpro.html":  //生成新产品页
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['newpro']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_newpro}",$ls_newpro,$content);
		break;
		
		case "links.html":  //友情链接页
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['links']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$linkssql="select * from ls_links where enable=1 order by linkNum asc";
		$linksquery=$opendb->query($linkssql);
		$links_str = "";
		while($linksitem=mysql_fetch_assoc($linksquery)){			
			$links_str .= "<a href ='".$linksitem['linkURL']."' target='_blank'>".$linksitem['linkTitle']."</a> &nbsp; &nbsp; ";
		}
		$ls_links=$links_str;
		$content = str_replace("{ls_url}",$ls_links,$content);
		break;
		
		case "index_m":  //手机首页
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
			$inf_sql="select * from ls_information where inMenu = 'notice' order by ID";
			$inf_query=$opendb->query($inf_sql);
			$inf_row=mysql_fetch_array($inf_query);
			$content = str_replace("{ls_notice}",$inf_row['content'],$content);
			
			//首页工厂展示 Start
			$products_sql="select * from ls_workshop where enable=1 ";
			$products_sql.=" order by Num asc ";
			$products_query=$opendb->query($products_sql);
			$homework="";
			$i = 0;
			while($news_rows=mysql_fetch_assoc($products_query)){
				$homework.="<div class=\"col-lg-3 col-md-3 col-sm-6 col-xs-12\">
					<div ><a href=\"".$WorkShopFolders."/workshop-page".$news_rows['ID'].".html\"><img src=\"../".$WorkShopFolders."/images/".$news_rows['workshopPic']."\" class=\"img-thumbnail img-responsive\"/></a><div class=\"caption pro-name\"><a href=\"".$WorkShopFolders."/workshop-page".$news_rows['ID'].".html\">".$news_rows['workshopTitle']."</a></div></div>
				  </div>";
				$count++;
				$i++;
			}
			//首页工厂展示 End
			$content = str_replace("{ls_workshop}",$homework,$content);
			$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
		break;
		
		case "aboutus_m":  //手机端aboutus
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
			$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['about']."</li>";
			$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
			$content = str_replace("{ls_allabout}",$mainpart,$content);
			$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
		break;
		
		case "news_m":  //手机端新闻列表
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\" style='text-transform : capitalize;'>".$lan['news']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_newslist}",$mainpart,$content);
		$content = str_replace("{newstag}",$newstag,$content);
		$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
		break;
		
		case "faq_m":   //手机端常见问题
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\" style='text-transform : capitalize;'>".$lan['faq']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_newslist}",$mainpart,$content);
		$content = str_replace("{newstag}",$newstag,$content);
		$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
		break;
		
		case "download_m": //手机端生成下载
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['download']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_downlist}",$mainpart,$content);
		break;
		
		case "createdfile_m":  //手机端
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
			$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
		break;
		
		case "workshop_m":  //手机端工厂
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
			$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
			$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['workshop']."</li>";
			$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
			$content = str_replace("{ls_propage}",$ls_propage,$content);
			$content = str_replace("{ls_list}",$mainpart,$content);
			$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "certificate_m":  //手机端认证
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
			$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
			$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['certificate']."</li>";
			$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
			$content = str_replace("{ls_propage}",$ls_propage,$content);
			$content = str_replace("{ls_list}",$mainpart,$content);
			$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "qualitycontrol_m":  //手机端质量控制
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
			$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
			$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['quality']."</li>";
			$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
			$content = str_replace("{ls_propage}",$ls_propage,$content);
			$content = str_replace("{ls_list}",$mainpart,$content);
			$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "packing_m":   //手机端包装
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
			$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
			$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['packing']."</li>";
			$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
			$content = str_replace("{ls_propage}",$ls_propage,$content);
			$content = str_replace("{ls_list}",$mainpart,$content);
			$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		
		case "contactus_m":  //手机端联系我们
		$ls_lineno=__LINE__.(__FUNCTION__==""?"":"， 函数：".__FUNCTION__).(__CLASS__==""?"":"， 类：".__CLASS__);
		$content = str_replace("{ls_weibo}",$ls_facebook_twitter_m,$content);
		$ls_indicatebar = "<li><a href=\"index.html\">".$lan['home']."</a></li>
                           <li class=\"active\">".$lan['contact']."</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		$content = str_replace("{ls_contact}",$mainpart,$content);
		
		$content = str_replace("{contact_tel}",$contact_array['contact_tel'],$content);
		$content = str_replace("{contact_email}",$contact_array['contact_email'],$content);
		$content = str_replace("{contact_qq}",$contact_array['contact_qq'],$content);
		$content = str_replace("{contact_fax}",$contact_array['contact_fax'],$content);
		$content = str_replace("{contact_skype}",$contact_array['contact_skype'],$content);
		$content = str_replace("{contact_http}",$contact_array['contact_http'],$content);
		$content = str_replace("{contact_name}",$contact_array['contact_name'],$content);
		$content = str_replace("{contact_address}",$contact_array['contact_address'],$content);
		$content = str_replace("{contact_companyname}",$contact_array['contact_companyname'],$content);
		
		break;

	}
	$content = str_replace("{ls_links}",$ls_links,$content);
	$content = str_replace("{ls_weibo}",$ls_facebook_twitter,$content);
	
	if($translate != ''){
		//翻译代码
		$folder_name = $translate;
		$r_name = deep_in_array($folder_name, $translate_name);

		$translateFile = "../".$r_name['folder_name'];
		createFolder($translateFile);
		$transFile = str_replace("../", "", $filename);
		$content = str_replace("require_once('ls_admin", "require_once('../ls_admin", $content);
		$content = str_replace("require('ls_admin", "require('../ls_admin", $content);
		$content = str_replace("include('ls_admin/widget/sendmail_inc.php", "include('../ls_admin/widget/sendmail_inc_ml.php", $content);
		$content = str_replace("ls_admin/vplayer/cmpn.swf", $mutiLangDomianFlag."ls_admin/vplayer/cmpn.swf", $content);
		
		if( ifNeedTrans($translateFile."/".$transFile,$translate)||$_SESSION['transAll']==1){  //新闻等其他二级页（列表页，含手机）不存在和模拟翻译要生成，或者覆盖

			  if(translateApp($content, $translateFile."/".$transFile, $r_name['translate_name'])){
				  echo "创建 <a href='".$translateFile."/".$transFile."'>".$translateFile."/".$transFile."</a>成功！<a href=\"temp.php?ls=normal\"><u>返回</u></a>";  if($ls_debug) echo " - - -  - - - - - -  - - - ".basename($_SERVER['PHP_SELF'])."  行号  ".__LINE__ ;
				  echo "<br><br>";
	  
			  }else{
				  if($ls_debug) echo "生成文件".$translateFile."/".$transFile."失败！<br>";
			  }
				}
		else
		{echo "<a href='".$translateFile."/".$transFile."' target='_blank'>".$translateFile."/".$transFile."</a> 已存在， ".($_SESSION['transAll']==0?" 未生成。</br>":" ");}

	
	}else{
		//英文网站去除<translate>标签
		$translate_str = $content;
		$p = "%<translate>(.*?)</translate>%si";    //正则表达式
		preg_match_all($p, $content, $arr);
		$temarr = $arr[1];
		
		$source="en";
		$targets = $target;
	
		foreach($temarr as $val){
			$content = str_replace("<translate>".$val."</translate>", $val, $content);
		}
		  
		$handle = fopen($filename,"w"); //打开文件指针，
		//var_dump($filename);exit;
			  /*
			　检查文件是否被创建且可写
			  */
			
		if (!is_writable ($filename))
		{ 
			if($ls_debug) echo "<script>alert('文件：".$filename."不可写，请检查其属性后重试！');history.go(-1);</script>";
		}
		if (!fwrite ($handle,$content))
		{  //将信息写入文件
			if($ls_debug) echo "<script>alert('生成文件".$filename."失败！');history.go(-1);</script>";
		}
		
		fclose ($handle); //关闭指针
		$target = "target='_blank'";

		// if(strpos($filename, "index.html") !== false){
		//	 $target = "target='_blank'";
		// }else{
		//	 $target = "";
		// }
		echo "创建 <a href='".$filename."' ".$target." >".$filename."</a>成功！<a href=\"temp.php?ls=normal\"><u>返回</u></a>";
		if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;

		echo "<br/><br/>";
	}
	fclose($fp);	//关闭文件指针
}
/*
------------------------------------------------------
参数：
$filename 
&$str  content str 的引用

程序功能：写入类下产品页ini文件
------------------------------------------------------
*/
function writegeneralfile($filename,&$str)// 避免字符串太大不方便传递值，只传递引用
{
	$content=$str;
	if (is_file ($filename))
	{ 
	   @unlink ($filename); //若文件已存在，则删除
	}

	$handle   = fopen($filename,"w"); //打开文件指针，
		  /*
		　检查文件是否被创建且可写
		  */
	if (!is_writable ($filename))
	{ 
		echo "文件：".$filename."不可写，请检查其属性后重试！";
	}
	if (!fwrite ($handle,$content))
	{  //将信息写入文件
		//echo " 写入文件".$filename."失败！"
		return false;
	} 
	else
	{ 
		return true;
		//echo " 写入".$filename." 成功<br>";
	}

	fclose ($handle); //关闭指针
					  //die ("创建<a href='".$filename."'>".$filename."</a>成功！<a href=\"temp.php?ls=normal\"><u>返回</u></a>");

}

	/*
------------------------------------------------------
参数：
$varstr   	变量名
$valuestr 	变量值变量类型 str
$vartype 	 or 
参数举例	 	writeconstant("lsVer", 1.181 ,"int","","//----版本号参数");	
程序功能：	写入参数文件函数 constant
如果没有插入标志，先插入插入标志;如果没有这个变量，那么 插入这个变量
------------------------------------------------------
*/

function writeconstant($varstr,$valuestr,$vartype,$oprconstant="modify",$insertflag="//----insert flag9",$filename="../ls_admin/inc/constant.php")
{
	
	$handle = fopen($filename,"r");
	$partstr="";
	$partstr0="";
	$modifyOK=false;	//是否成功修改，插入
	while (!feof ($handle)) 
	{
		$partstr0 =  fgets ($handle, 3000);
		//echo rawurlencode($partstr0);
		if(($oprconstant=="modify" || $oprconstant=="" )&& strpos(trim($partstr0),"\$".$varstr."=")===0 )  // 空参数认为是modify
		{
			if($vartype=="str")
			{$partstr0="	\$".$varstr."=\"".$valuestr."\";\r\n";}
			else
			{$partstr0="	\$".$varstr."=".$valuestr.";\r\n";}
			$modifyOK=true;
		}
		
		if($oprconstant=="insert" && strpos(trim($partstr0),$insertflag)===0 && strpos($partstr0,$insertflag."end")===false  )	//插入标志行后面
		{
			//echo (strlen($insertflag)+strpos($partstr0,$insertflag))."mm".strlen($partstr0).$partstr0; exit;
			if($vartype=="str")
			{$partstr0="	\$".$varstr."='".$valuestr."';\r\n";}
			else
			{$partstr0="	\$".$varstr."=".$valuestr.";\r\n";}	
			$partstr0="	".$insertflag."\r\n".$partstr0;
			$modifyOK=true;
		}

		$partstr.=$partstr0;
	}
	//echo strlen($partstr);
	fclose ($handle);
	
	if(!$modifyOK && $oprconstant=="insert")  //如果没有插入标志，先插入插入标志
	{
		if($vartype=="str")
		{$partstr0="	\$".$varstr."=\"".$valuestr."\";\r\n";}
		else
		{$partstr0="	\$".$varstr."=".$valuestr.";\r\n";}	
		$partstr0="\r\n	".$insertflag."\r\n".$partstr0;
		$partstr=str_replace("?>",$partstr0."?>",$partstr);
		$modifyOK=true;
	}
	
	writegeneralfile($filename,$partstr); // write the constant.php
	if(!$modifyOK) writeconstant($varstr,$valuestr,$vartype,"insert",$insertflag,$filename);  //如果没有修改成功，则没有这个变量，那么 插入这个变量
	
}

/*
------------------------------------------------------
参数：
$currentProgram   目前运行程序
$currentFunction 目前功能
$parameter  参数
程序功能：写入日志函数
------------------------------------------------------
*/

function writelog($currentProgram,$currentFunction,$parameter,$username='admin')
{
	require_once('conn.php');
	global $logSpace,$logStat;
	if($logStat=='stop'){return;}

	$opendb=new mydb();
	require('char_set.php');
	

	$select_sql2="select * from ls_log ";
	$select_query2=$opendb->query($select_sql2);
	$select_rows2=mysql_num_rows($select_query2); //总数

	if($select_rows2>=$logSpace)
	{
		$del_sql="delete  from  ls_log where 1 limit 30";
		$insert_query=$opendb->query($del_sql);	
	}
	$currentFunction=str_replace("'","`",$currentFunction);

	$insert_sql="insert into ls_log(currentDateTime,currentProgram,currentFunction,parameter,memo,ip,username) values ('".date('Y-m-d G:i:s')."','".$currentProgram."','".$currentFunction."','".$parameter."','','".$_SERVER['REMOTE_ADDR']."','".$username."')";
	//echo $insert_sql;
	$insert_query=$opendb->query($insert_sql);	
}

/*
------------------------------------------------------
参数：
$querys   传递进入的查询结果
$srDirection 排序方向，目前本参数不起作用
程序功能：对传入的查询结果中的Num字段进行降序赋值。
注意：请不要随意调用本函数，本函数是为之后的排序函数缩减重复代码所设立。
------------------------------------------------------
*/

function SortRows($querys,$srDirection){
	$sortdb=new mydb();
	$totalRows=mysql_num_rows($querys);
	while($queryRows=mysql_fetch_assoc($querys)){
		$updateSql="update ls_products set Num=".$totalRows." where ID=".$queryRows['ID']." ";
		$updateQuery=$sortdb->query($updateSql);
		$totalRows--;
	}
}

/*
------------------------------------------------------
参数：
$spCate   排序产品所属的大类ID
$spMidCate 排序产品所属的中类ID
$spSubCate  排序产品所属的小类ID
$spKind  排序所采用的字段名称
$spDirection  排序方向
$ignore  是否开启整类排序功能
程序功能：对指定的类别中的产品进行批量排序。
注意：本函数中部分参数直接参与SQL语句的组装，直接键入参数时请注意格式是否正确。Products.php文件中的参数指定均为预先固定的，可参考。
------------------------------------------------------
*/
function SortPros($spCate,$spMidCate,$spSubCate,$spKind,$spDirection,$ignore,$onlyGrandCate){
	$sortdb=new mydb();
	if($spCate!="" && $spMidCate=="" && $spSubCate=="" )
	{
		$sortSql="select * from ls_products where productID=".$spCate." order by ".$spKind." ".$spDirection." ";
		//echo $sortSql;
		$sortQuery=$sortdb->query($sortSql);
		SortRows($sortQuery,$spDirection);
	}
	
	if($spCate!="" && $spMidCate!="" && $spSubCate=="" )
	{
		$sortSql="select * from ls_products where productID=".$spMidCate." order by ".$spKind." ".$spDirection." ";
		$sortQuery=$sortdb->query($sortSql);
		SortRows($sortQuery,$spDirection);
	}

	if($spCate!="" && $spMidCate!="" && $spSubCate!="" )
	{
		$sortSql="select * from ls_products where productID=".$spSubCate." order by ".$spKind." ".$spDirection." ";
		$sortQuery=$sortdb->query($sortSql);
		SortRows($sortQuery,$spDirection);
	}
	return true;
}
/*
function SortPros($spCate,$spMidCate,$spSubCate,$spKind,$spDirection,$ignore,$onlyGrandCate){
	$sortdb=new mydb();
	if($onlyGrandCate){
		if($spCate==-1){
			echo "<script language='javascript'>alert('请先进入要排序的类别。'); location.href='products.php';</script>";
		} else {
			$sortSql="select * from ls_products where productID=".$spCate." order by ".$spKind." ".$spDirection." ";
			$sortQuery=$sortdb->query($sortSql);
			SortRows($sortQuery,$spDirection);
		}
		return true;
	}
	if($ignore){
		if($spSubCate==-1){
			if($spMidCate==-1){
				echo "<script language='javascript'>alert('请先进入要排序的类别。'); location.href='products.php';</script>";
			} else {
				$totalSql="select * from ls_products where subcateID=".$spMidCate." ";
				$totalQuery=$sortdb->query($totalSql);
				$sortSql="select * from ls_products where (";
				$conFlagi=0; 
				if(mysql_num_rows($totalQuery)!=0){
					while($totalRow=mysql_fetch_assoc($totalQuery)){
						if($conFlagi==0){
							  $sortSql.="productID=".$totalRow['ID'];
						} else {
							  $sortSql.=" or productID=".$totalRow['ID'];
						}
						$conFlagi++;
					}
				} else {
					$sortSql.="productID=".$spMidCate;
				}
				$sortSql.=") order by ".$spKind." ".$spDirection." ";	
				$sortQuery=$sortdb->query($sortSql);
				SortRows($sortQuery,$spDirection);
			}
		} else {
			$sortSql="select * from ls_products where productID=".$spSubCate." order by ".$spKind." ".$spDirection." ";
			$sortQuery=$sortdb->query($sortSql);
			SortRows($sortQuery,$spDirection);
		}
	} else {
		if($spSubCate==-1){
			if($spMidCate==-1){
				echo "<script language='javascript'>alert('请先进入要排序的类别。'); location.href='products.php';</script>";
			} else {
				$checkSubCateSql="select ID from ls_products where subcateID=".$spMidCate." ";
				$checkSubCateQuery=$sortdb->query($checkSubCateSql);
				if(mysql_num_rows($checkSubCateQuery)!=0){
					echo "<script language='javascript'>alert('非法跨类排序操作，排序中止，程序返回。');location.href='products.php?cateid=".$spCate."&midcateid=".$spMidCate."';</script>";
				} else {
					$sortSql="select * from ls_products where productID=".$spMidCate." order by ".$spKind." ".$spDirection." ";
					$sortQuery=$sortdb->query($sortSql);
					SortRows($sortQuery,$spDirection);
				}
			}
		} else {
			$sortSql="select * from ls_products where productID=".$spSubCate." order by ".$spKind." ".$spDirection." ";
			$sortQuery=$sortdb->query($sortSql);
			SortRows($sortQuery,$spDirection);
		}
	}
	return true;
}

*/

/*
------------------------------------------------------
参数：

程序功能：格式化输出变量内容。用于调试。
------------------------------------------------------
*/

function dump()
{
	$argAmount=func_num_args();
	if ($argAmount==0)
	{
		echo "<pre>";
		echo "Arguements can NOT be empty.";
		echo "</pre>";
	}
	else 
	{
		ob_start();
		echo "<pre>";
		for($i=0;$i<$argAmount;$i++)
		{
			echo "Arguement ".($i+1)."<br>";
			var_dump(func_get_arg($i));
			echo "<br>";
		}
		echo "</pre>";
		$output=ob_get_clean();
		$output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
		echo $output;
	}
}

/*
------------------------------------------------------
参数：

程序功能：对类别进行扫描，并对有错误的类别进行纠正。
------------------------------------------------------
*/

function scancates()
{
	$opdb=new mydb();
	$startsql="select ID from ls_products where cateName is not null order by Num asc, ID asc";
	$startq=$opdb->query($startsql);
	$sentryi=1;
	while($gcate=mysql_fetch_assoc($startq))
	{
		repairseq($gcate['ID'],$sentryi);
		$secondsql="select ID from ls_products where midcateName is not null and midcateID='{$gcate['ID']}' order by Num asc, ID asc";
		$secondq=$opdb->query($secondsql);
		$sentryj=1;
		while($mcate=mysql_fetch_assoc($secondq))
		{
			repairseq($mcate['ID'],$sentryj);
			$thirdsql="select ID from ls_products where subcateID is not null and subcateID={$mcate['ID']} order by Num asc, ID asc";
			$thirdq=$opdb->query($thirdsql);
			$sentryk=1;
			while($scate=mysql_fetch_assoc($thirdq))
			{
				repairseq($scate['ID'],$sentryk);
				$sentryk++;
			}
			$sentryj++;
		}
		$sentryi++;
	}
}

/*
------------------------------------------------------
参数：	$opid		要操作的记录ID
		$opnum		设定的数值

返回值：无

程序功能：重新将指定ID的Num字段赋值，此为复杂功能拆解模块，请勿直接调用
------------------------------------------------------
*/

function repairseq($opid,$opnum)
{
	$opdb=new mydb();
	$resetsql="update ls_products set Num={$opnum} where ID={$opid}";
	$resetq=$opdb->query($resetsql);
}

/*
------------------------------------------------------
参数：	$opid		查询产品ID

返回值：布尔值

程序功能：查询与产品是否有同级别的类别，有返回真，无返回假。
------------------------------------------------------
*/

function hassameclass($opid)
{
	$opdb=new mydb();
	$checksql="select * from ls_products where midcateID='{$opid}' or subcateID={$opid}";
	$checkq=$opdb->query($checksql);
	if(mysql_num_rows($checkq)!=0){
		return true;
	}else{
		return false;
	}
}

 // 作用取得客户端的ip、地理信息、浏览器、本地真实IP
 class get_gust_info { 
  
  ////获得访客浏览器类型
  function GetBrowser(){
   if(!empty($_SERVER['HTTP_USER_AGENT'])){
    $br = $_SERVER['HTTP_USER_AGENT'];
    if (preg_match('/MSIE/i',$br)) {    
               $br = 'MSIE';
             }elseif (preg_match('/Firefox/i',$br)) {
     $br = 'Firefox';
    }elseif (preg_match('/Chrome/i',$br)) {
     $br = 'Chrome';
       }elseif (preg_match('/Safari/i',$br)) {
     $br = 'Safari';
    }elseif (preg_match('/Opera/i',$br)) {
        $br = 'Opera';
    }else {
        $br = 'Other';
    }
    return $br;
   }else{return "获取浏览器信息失败！";} 
  }
  
////获得访客浏览器语言
function GetLang(){
if(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = substr($lang,0,5);
if(preg_match("/zh-cn/i",$lang)){
 $lang = "简体中文";
}elseif(preg_match("/zh/i",$lang)){
 $lang = "繁体中文";
}else{
	$lang = "English";
}
return $lang;

}else{return "获取浏览器语言失败！";}
}

////获取访客操作系统
function GetOs(){
if(!empty($_SERVER['HTTP_USER_AGENT'])){
$OS = $_SERVER['HTTP_USER_AGENT'];
  if (preg_match('/win/i',$OS)) {
 $OS = 'Windows';
}elseif (preg_match('/mac/i',$OS)) {
 $OS = 'MAC';
}elseif (preg_match('/linux/i',$OS)) {
 $OS = 'Linux';
}elseif (preg_match('/unix/i',$OS)) {
 $OS = 'Unix';
}elseif (preg_match('/bsd/i',$OS)) {
 $OS = 'BSD';
}else {
 $OS = 'Other';
}
	  return $OS;  
}else{return "获取访客操作系统信息失败！";}   
}

////获得访客真实ip
function Getip(){
if(!empty($_SERVER["HTTP_CLIENT_IP"])){   
  $ip = $_SERVER["HTTP_CLIENT_IP"];
}
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ //获取代理ip
$ips = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
}
if($ip){
  $ips = array_unshift($ips,$ip); 
}

$count = count($ips);
for($i=0;$i<$count;$i++){   
 if(!preg_match("/^(10|172\.16|192\.168)\./i",$ips[$i])){//排除局域网ip
  $ip = $ips[$i];
  break;    
  }  
}  
$tip = empty($_SERVER['REMOTE_ADDR']) ? $ip : $_SERVER['REMOTE_ADDR']; 
if($tip=="127.0.0.1"){ //获得本地真实IP
  return $this->get_onlineip();   
}else{
  return $tip; 
}
}

////获得本地真实IP
function get_onlineip() {
  $mip = file_get_contents("http://city.ip138.com/city0.asp");
   if($mip){
	   preg_match("/\[.*\]/",$mip,$sip);
	   $p = array("/\[/","/\]/");
	   return preg_replace($p,"",$sip[0]);
   }else{return "获取本地IP失败！";}
}

////根据ip获得访客所在地地名
function Getaddress($ip=''){
if(empty($ip)){
   $ip = $this->Getip();    
}
$ipadd = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=".$ip);//根据新浪api接口获取
if($ipadd){
$charset = iconv("gbk","utf-8",$ipadd);   
preg_match_all("/[\x{4e00}-\x{9fa5}]+/u",$charset,$ipadds);

return $ipadds;   //返回一个二维数组
}else{return "addree is none";}  
} 
}

/*
------------------------------------------------------
参数：
$productID		当前页新闻id
$direction		跳转方向(值:'F'下一条,'B'上一条)
$tag			替换标签
$content		需要处理的内容
$db				数据库名
$cate			分类名称

返回值：替换完成的内容

程序功能：将指定标签替换成向前翻页以及向后翻页的链接

备注：仅支持本类中的页面跳转，不支持类间的。
------------------------------------------------------
*/
/*
function circleNavigationLinkNews($ID,$direction,$tag,$content,$db,$cate,$fileName,$suffix_str,$catebool){
	
	$opdb=new mydb();
	//Get product information
	require('inc/constant.php');
	$lan = array();
	if($lang != "en"){
		$lan = $lang_cn;
	}else{
		$lan = $lang_en;
	}
	$productInfoSql="select * from $db where ID={$ID}";
	$productInfoR=$opdb->query($productInfoSql);
	$productInfo=mysql_fetch_object($productInfoR);
	//Get Max and Min Num value
	if($catebool){
		$numLimitSql="select min(Num) as minNum, max(Num) as maxNum from $db where cate='$cate' and enable ='1'";
	}else{
		$numLimitSql="select min(Num) as minNum, max(Num) as maxNum from $db where enable ='1'";
	}
	$numLimitR=$opdb->query($numLimitSql);
	$numLimit=mysql_fetch_object($numLimitR);	
	//According to $direction, search the next product
	if(($productInfo->Num==$numLimit->minNum)&&('B'==strtoupper($direction))){
		$linkProductNum=$numLimit->maxNum;
	}else if(($productInfo->Num==$numLimit->maxNum)&&('F'==strtoupper($direction))){
		$linkProductNum=$numLimit->minNum;
	}else{
		$searchCount=0;
		do{
			$searchCount++;
			$linkProductNum=('B'==strtoupper($direction))?($productInfo->Num-$searchCount):($productInfo->Num+$searchCount);
			if($catebool){
				$checkSql="select ID from $db where cate='$cate' and enable ='1' and Num={$linkProductNum}";
			}else{
				$checkSql="select ID from $db where enable ='1' and Num={$linkProductNum}";
			}
			$checkR=$opdb->query($checkSql);
		}while(0==mysql_num_rows($checkR));
	}
	//Get target product information and return the ready content
	if($catebool){
		$targetProductSql="select * from $db where cate='$cate' and enable ='1' and Num={$linkProductNum}";
	}else{
		$targetProductSql="select * from $db where enable ='1' and Num={$linkProductNum}";
	}
	$targetProductR=$opdb->query($targetProductSql);
	$targetProduct=mysql_fetch_object($targetProductR);
	if($catebool){
		$targetProductFile=$fileName.$suffix_str.$targetProduct->ID.".html";
		$targetProductLink="<a href=\"{$targetProductFile}\">".(('B'==strtoupper($direction))?$lan['previous']:$lan['next'])."</a>";
	}else{
		$targetProductFile=$fileName."-page".$targetProduct->ID.".html";
		$targetProductLink="<a href=\"{$targetProductFile}\">".(('F'==strtoupper($direction))?$lan['previous']:$lan['next'])."</a>";
	}
	return str_replace($tag,$targetProductLink,$content);
}*/

//文章详页  跳转方向(值:'B'下一条,'F'上一条) $direction 方向 $db 数据库名 $functionName 大类 $cate 小类 $filename 文件名 $str_list 类别ID $catebool 是否跨小类
function circleNavigationLinkNews($ID,$direction,$tag,$content,$db,$cate,$fileName,$suffix_str,$catebool){
	$opdb=new mydb();
	//Get product information
	require('inc/constant.php');
	$lan = array();
	if($lang != "en"){
		$lan = $lang_cn;
	}else{
		$lan = $lang_en;
	}
	$opdb=new mydb();
	//Get product information
	$productInfoSql="select * from $db where ID={$ID}";
	$productInfoR=$opdb->query($productInfoSql);
	$productInfo=mysql_fetch_object($productInfoR);
	
	//Get Max and Min Num value
	if($catebool){
		$numLimitSql="select min(Num) as minNum, max(Num) as maxNum from $db where cate='$cate' and enable ='1'";
	}else{
		$numLimitSql="select min(Num) as minNum, max(Num) as maxNum from $db where enable ='1'";
	}
	$numLimitR=$opdb->query($numLimitSql);
	$numLimit=mysql_fetch_object($numLimitR);
	//According to $direction, search the next product
	if(($productInfo->Num==$numLimit->minNum)&&('B'==strtoupper($direction))){
		$linkProductNum=$numLimit->maxNum;
	}else if(($productInfo->Num==$numLimit->maxNum)&&('F'==strtoupper($direction))){
		$linkProductNum=$numLimit->minNum;
	}else{
		$searchCount=0;
		do{
			$searchCount++;
			$linkProductNum=('B'==strtoupper($direction))?($productInfo->Num-$searchCount):($productInfo->Num+$searchCount);

			if($catebool){
				$checkSql="select * from $db where cate='$cate' and enable ='1' and Num={$linkProductNum}";
			}else{
				$checkSql="select * from $db where enable ='1' and Num={$linkProductNum}";
			}

			$checkR=$opdb->query($checkSql);
			$targetProduct=mysql_fetch_object($checkR);
			if(mysql_num_rows($checkR) != 0){
				if($catebool){
					$targetProductFile=$fileName.$suffix_str.$targetProduct->ID.".html";
					$targetProductLink="<a href=\"{$targetProductFile}\">".(('F'==strtoupper($direction))?$lan['previous']:$lan['next'])."</a>";
				}else{
					$targetProductFile=$fileName.$targetProduct->ID.".html";
					$targetProductLink="<a href=\"{$targetProductFile}\">".(('F'==strtoupper($direction))?$lan['previous']:$lan['next'])."</a>";
				}
			}
		}while(0==mysql_num_rows($checkR));
	}
	//Get target product information and return the ready content
	return str_replace($tag,$targetProductLink,$content);
}

/*------------------------------------------------------
//  递归建立文件夹及子文件夹
//　使用方法crmkdir($folder)  $folder 多级文件夹
------------------------------------------------------*/
function crmkdir($folder)
{
	$mkfolder="";
	$allfolder=explode("/",$folder);
	for($i=0;$i<= count($allfolder);$i++)
	{
		if($allfolder[$i]=="..")
		{
			if($i==0)
			{
				$mkfolder=$allfolder[$i];
			}
			else
			{
				$mkfolder=$mkfolder."/".$allfolder[$i];
			}
		}
		else
		{
			$mkfolder=$mkfolder."/".$allfolder[$i];
			//echo 	$mkfolder."--";
			if(!file_exists($mkfolder))
			{
				mkdir($mkfolder);
			}
		}
		
	}
	
}

/*
getStrbyTag 通过匹配首串 和尾串 获得中间首串 和尾串 的字符串
$headTag,$tailTag 首串和尾串
true 包括首尾串
返回获得的串
$imgwidth=getStrbyTag('width=',' ',$newsImgStr,false);
*/

function getStrbyTag($headTag,$tailTag,$str,$includeHeadTail=true)
{
		$midStr=substr($str,strpos($str,$headTag),strlen($str));
		$gotStr=strtolower(substr($midStr,0,strpos($midStr,$tailTag)+strlen($tailTag)));
		
		if(!$includeHeadTail)
		{
			$gotStr=str_replace($headTag,"",$gotStr);
			$gotStr=str_replace($tailTag,"",$gotStr);
			
		}
		//echo "1--".$gotStr."--1";
		return $gotStr;
}

/*
根据产品分类ID获得产品的图片路径 和 链接
返回$propiclink  路径 和 链接 数组
*/
function getpiclink($productID,$productpic)
{
	require_once('conn.php');
	$opendb=new mydb();
	require_once('char_set.php');
	global $SmallFoldersProducts,$showproductsFolders;
	if($productID=="")return; //没有跳过

	$pic_sql="select * from ls_products where ID=".$productID." ";
	$pic_query=$opendb->query($pic_sql);
	$pic_myrows=mysql_fetch_assoc($pic_query);


	if($pic_myrows['subcateFolders']=="")
	{
		if($pic_myrows['midcateFolders']=="") //产品在大类下
		{
			$picsrc=$pic_myrows['cateFolders']."/".$SmallFoldersProducts."/".$productpic;
			$piclink=$pic_myrows['cateFolders']."/".trim(str_replace(substr($productpic,-4),"",$productpic)).".html";
		}
		else//产品在中类下
		{
		
			$pic_sql="select * from ls_products where ID=".$pic_myrows['midcateID']."";
			$pic_query=$opendb->query($pic_sql);
			$pic_myrows2=mysql_fetch_assoc($pic_query);

			$picsrc=$pic_myrows2['cateFolders']."/".$pic_myrows['midcateFolders']."/".$SmallFoldersProducts."/".$productpic;
			$piclink=$pic_myrows2['cateFolders']."/".$pic_myrows['midcateFolders']."/".trim(str_replace(substr($productpic,-4),"",$productpic)).".html";
		}
	}
	else//产品在小类下
	{
			$pic_sql="select * from ls_products where ID=".$pic_myrows['subcateID']."";
			$pic_query=$opendb->query($pic_sql);
			$pic_myrows2=mysql_fetch_assoc($pic_query);

			$pic_sql="select * from ls_products where ID=".$pic_myrows2['midcateID']."";
			$pic_query=$opendb->query($pic_sql);
			$pic_myrows3=mysql_fetch_assoc($pic_query);
			
			$picsrc=$pic_myrows3['cateFolders']."/".$pic_myrows2['midcateFolders']."/".$pic_myrows['subcateFolders']."/".$SmallFoldersProducts."/".$productpic;
			$piclink=$pic_myrows3['cateFolders']."/".$pic_myrows2['midcateFolders']."/".$pic_myrows['subcateFolders']."/".trim(str_replace(substr($productpic,-4),"",$productpic)).".html";
	}	
	
	//echo $ID.$picsrc."--".$piclink;
	//die();
	$propiclink=array("picsrc"=>$picsrc,"piclink"=>$piclink);
	return $propiclink;
}

/*
//生成新闻、证书、工厂、品牌、质量等详细页
//参数为查询出的一条记录

*/
function writeShowPages($news_rows, $suffix_str2, $cateName, $s_table, $menu_pro, $pro_cate, $s_pro_cate, $s_m2_cate, $ls_propage, $facebook_twitter, $s_site_cate, $foot, $ls_addprolink, $ls_addnewprolink, $ls_h_news, $s_p_cate, $ls_languages, $get_pro_cate, $indicatebarpath, $translate){
	
	require_once('conn.php');
	$opendb=new mydb();
	require_once('char_set.php');
	require('constant.php');
	require('switchShowPage.php');
	
	if($lang != "en"){
		$lan = $lang_cn;
	}else{
		$lan = $lang_en;
	}
	$tem_sql="select * from ls_config order by ID";	
	$tem_query=$opendb->query($tem_sql);
	$row=mysql_fetch_array($tem_query);

	$facebook_twitter = str_replace("YOUR-FACEBOOK",$row['facebook'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-TWITTER",$row['twitter'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-LINKEDIN",$row['linkedin'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-GOOGLE",$row['google'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-PINTEREST",$row['pinterest'],$facebook_twitter);
	$facebook_twitter = str_replace("YOUR-YOUTUBE",$row['youtube'],$facebook_twitter);
	//$facebook_twitter = str_replace("../","",$facebook_twitter);
	
	$code_sql="select * from ls_functioncode where enable=1 order by ID";	
	$opendb=new mydb();
	$code_query=$opendb->query($code_sql);
	while ($code_row=mysql_fetch_array($code_query)){
		switch($code_row['codeID']){
			case "statistics":
				if($code_row['enable']){
					$statistics = $code_row['code'];
				}
			break;
			case "onlines":
				if($code_row['enable']){
					$onlines = $code_row['code'];
				}
			break;
			case "maps":
				if($code_row['enable']){
					$maps = $code_row['code'];
				}
			break;
			case "share":
				if($code_row['enable']){
					$share = $code_row['code'];
				}
			break;
			case "indexKeywords":
				if($code_row['enable']){
					$indexKeywords = $code_row['code'];
				}
			break;
			case "onlinechart":
				if($code_row['enable']){
					$onlinechart = $code_row['code'];
				}
			break;
			case "shield":
				if($code_row['enable']){
					$shield = $code_row['code'];
				}
			break;
		}
	}
	
	$newstag=$news_rows['cate'];
	//$newstitle="<translate>".$news_rows[$s_title]."</translate>";  翻译代码
	//$newstext="<translate>".$news_rows[$s_text]."</translate>";
	$newstitle=$news_rows[$s_title];   //不翻译代码
	$clickTotal=$news_rows['ID']; //浏览量  新闻id
	$newstext=$news_rows[$s_text];
	$managerweibo = "";
	if($news_rows['facebook']!= ''){
		$managerweibo .= "<a href='".$news_rows['facebook']."' style='border: 0px; width:auto; height:auto; padding:2px;'><img src='../ls_admin/images/social_ico/facebook.jpg' /></a>";
	}
	if($news_rows['twitter']!= ''){
		$managerweibo .= "<a href='".$news_rows['twitter']."' style='border: 0px; width:auto; height:auto; padding:2px;'><img src='../ls_admin/images/social_ico/twitter.jpg' /></a>";
	}
	if($news_rows['linkedin']!= ''){
		$managerweibo .= "<a href='".$news_rows['linkedin']."' style='border: 0px; width:auto; height:auto; padding:2px;'><img src='../ls_admin/images/social_ico/linkedin.jpg' /></a>";
	}
	if($news_rows['google']!= ''){
		$managerweibo .= "<a href='".$news_rows['google']."' style='border: 0px; width:auto; height:auto; padding:2px;'><img src='../ls_admin/images/social_ico/google+.jpg' /></a>";
	}
	$newsdetail = "<table width=\"500\" border=\"0\" align=\"center\">
		  <tr>
			<td><b>Name:</b> ".$news_rows['name']."</td>
			<td><b>Post:</b> ".$news_rows['post']."</td>
		  </tr>
		  <tr>
			<td><b>Department:</b> ".$news_rows['department']."</td>
			<td><b>Tel:</b> ".$news_rows['tel']."</td>
		  </tr>
		  <tr>
			<td><b>Mobile:</b> ".$news_rows['mobile']."</td>
			<td><b>Email:</b> <a href='mailto:".$news_rows['email']."'>".$news_rows['email']."</a></td>
		  </tr>
		  <tr>
			<td><b>Skype:</b> <a href='skype:".$news_rows['skype']."?chat'>".$news_rows['skype']."</a></td>
			<td><b>Whatsapp:</b> ".$news_rows['wechat']."</td>
		  </tr>
		  <tr>
			<td><b>QQ:</b> ".$news_rows['qq']."</td>
			<td>".$managerweibo."</td>
		  </tr>
		  <tr>
			<td colspan=\"2\"><b>Duty:</b> ".$news_rows['duty']."</td>
		  </tr>
		</table>";
	
	$newimg = "<center><img src=\"../".$showFolders."/".$BigFoldersProducts."/".$news_rows[$workshopPic]."\" ondragstart=\"return false;\" alt='".$newstitle."' title='".$newstitle."'/></center>";
	
	$ls_newstime = $news_rows[$s_newstime];
	$ls_newid = $news_rows['ID'];
	$ls_click_n = $news_rows['clickNum'];
	createFolder("../".$newsshowFolders);
	if($suffix_str2=="_dongtai" || $suffix_str2=="_gonggao" || $suffix_str2=="_tieshi" )
	{ $index_newspath="../".$templates_var."/newsshow".$suffix_str2.".html";	}
	else
	{
		$index_newspath="../".$templates_var."/".$cateName."show.html";		//模板地址
	}	
	$ls_title = $news_rows['newsTitle'];
	$ls_keywords = $news_rows['newsKeywords'];
	$ls_description = $news_rows['newsDescription'];
	If($cateName=="news"){
		  $ls_keywords = $news_rows['keywords'];
		  $ls_description = $news_rows['description'];
	}
	
	$ls_cate=$pro_cate;
	$ls_s_cate=$s_pro_cate;								//左侧产品类别;
	$ls_s_news = $ls_h_news;
	$ls_p_cate=$s_p_cate;								//左侧产品类别;
	$ls_f_cate=$get_pro_cate;
	$ls_motif=$s_m2_cate;
	$ls_menu=$menu_pro;									//主菜单
	$ls_newstitle=$newstitle ;							//新闻标题
	$ls_clickTotal=$clickTotal;//浏览量  新闻id
	$ls_newimg=$newimg;
	$ls_newsdetail = $newsdetail;
	$ls_newstext=$newstext;
	$ls_url="../";										//链接		
	$ls_foot=$foot;										//底部信息
	
	$fp	   = fopen ($index_newspath,"r");
	$newscontent = fread ($fp,filesize ($index_newspath));
	
	$newscontent = str_replace("{ls_statistics}",$statistics,$newscontent); //统计代码
	$newscontent = str_replace("{ls_onlines}",$onlines,$newscontent);  //在线联系(QQ)
	$newscontent = str_replace("{ls_maps}",$maps,$newscontent);  //地图代码
	$newscontent = str_replace("{ls_share}",$share,$newscontent);  //分享代码
	$newscontent = str_replace("{ls_onlinechart}",$onlinechart,$newscontent);  //在线联系
	$newscontent = str_replace("{ls_shield}",$shield,$newscontent);  //首页屏蔽
	
	$newscontent = str_replace("{ls_title}",$ls_title,$newscontent);
	$newscontent = str_replace("{ls_keywords}",$ls_keywords,$newscontent);
	$newscontent = str_replace("{ls_description}",$ls_description,$newscontent);
	$newscontent = str_replace("{ls_menu}",$ls_menu,$newscontent);
	$newscontent = str_replace("{ls_cate}",$ls_cate,$newscontent);
	$newscontent = str_replace("{ls_cate}",$ls_cate,$newscontent);
	$newscontent = str_replace("{ls_s_cate}",$ls_s_cate,$newscontent);
	$newscontent = str_replace("{ls_languages}",$ls_languages,$newscontent);
	$newscontent = str_replace("{ls_p_cate}",$ls_p_cate,$newscontent);
	$newscontent = str_replace("{ls_f_cate}",$ls_f_cate,$newscontent);
	$newscontent = str_replace("{ls_motif}",$ls_motif,$newscontent);
	$newscontent = str_replace("{ls_motif}",$ls_motif,$newscontent);
	$newscontent = str_replace("{ls_propage}",$ls_propage,$newscontent);
	$newscontent = str_replace("{ls_copyright}",$row['copyright'],$newscontent);
	
	$ls_facebook_twitter = $facebook_twitter;
	$newscontent = str_replace("{ls_weibo}",$ls_facebook_twitter,$newscontent);
	$ls_facebook_twitter_share = $facebook_twitter_share;
	$newscontent = str_replace("{ls_weiboshare}",$ls_facebook_twitter_share,$newscontent);
	
	$ls_indicatebar = "<li><a href=\"../index.html\">".$lan['home']."</a></li>
					   <li style='text-transform : capitalize;'><a href=\"../".$cateName.".html\">".$indicatebarpath."</a></li>";
	$newscontent = str_replace("{ls_indicatebar}",$ls_indicatebar,$newscontent);
	
	$newscontent = str_replace("{ls_news}",$ls_s_news,$newscontent);
	
	$newscontent = str_replace("{ls_newstime}",$ls_newstime,$newscontent);
	$newscontent = str_replace("{ls_newid}",$ls_newid,$newscontent);
	$newscontent = str_replace("{ls_click_n}",$ls_click_n,$newscontent);
	$newscontent = str_replace("{ls_newstitle}",$ls_newstitle,$newscontent);
	$newscontent = str_replace("{ls_clickTotal}",$ls_clickTotal,$newscontent);//浏览量
	$newscontent = str_replace("{ls_shield}",'',$newscontent);
	$newscontent = str_replace("{ls_newimg}",$ls_newimg,$newscontent);
	$newscontent = str_replace("{ls_newsdetail}",$ls_newsdetail,$newscontent);
	$newscontent = str_replace("{ls_newstext}",$ls_newstext,$newscontent);
	$newscontent = str_replace("{ls_newsdongtai}",$ls_newsdongtai2,$newscontent);		//子目录下新闻 
	$newscontent = str_replace("{ls_newsgonggao}",$ls_newsgonggao2,$newscontent);   //new
	$newscontent = str_replace("{ls_newsall}",$ls_newsall2,$newscontent);
	$newscontent = str_replace("{ls_newstieshi}",$ls_newstieshi2,$newscontent);
	$newscontent = str_replace("{ls_site_cate}",$s_site_cate,$newscontent);
	$newscontent = str_replace("{ls_url}",$ls_url,$newscontent);
	$newscontent = str_replace("{ls_foot}",$ls_foot,$newscontent);
	$newscontent = str_replace("{ls_addprolink}",$ls_addprolink,$newscontent);	//指向主菜单中的Products链接
	$newscontent = str_replace("{ls_addnewprolink}",$ls_addnewprolink,$newscontent);	//指向主菜单中的NewProducts链接
	
	if(strtolower($cateName) == "news" || strtolower($cateName) == "faq"  || strtolower($cateName) == "faqs"){
		$booleam = true;
	}else{
		$booleam = false;
	}
	
	$newscontent = circleNavigationLinkNews($news_rows['ID'],'B','{ls_nextlink}',$newscontent,"ls_".$s_table,$cate,$s_show,$suffix_str2,$booleam);
	$newscontent = circleNavigationLinkNews($news_rows['ID'],'F','{ls_previouslink}',$newscontent,"ls_".$s_table,$cate,$s_show,$suffix_str2,$booleam);
			
	//$filename="../".$showFolders."/".$s_show.$s_fileName.$news_rows['ID'].".html";
	$filename="../".$showFolders."/".$s_show.$suffix_str2.$news_rows['ID'].".html";
	createFolder("../".$showFolders);
	if($translate != ''){
		//翻译代码
		$folder_name = $translate;
		$r_name = deep_in_array($folder_name, $translate_name);

		$translateFile = "../".$r_name['folder_name'];
		createFolder($translateFile);
		createFolder("../".$r_name['folder_name']."/".$showFolders);
		$transFile = str_replace("../", "", $filename);
		
		if( ifNeedTrans($translateFile."/".$transFile,$translate)||$_SESSION['transAll']==1){  //新闻等其他三级页（详细页，不含手机）不存在和模拟翻译要生成，或者覆盖

			  if(translateApp($newscontent, $translateFile."/".$transFile, $r_name['translate_name'])){
				  echo "创建<a href='".$translateFile."/".$transFile."'>".$translateFile."/".$transFile."</a>成功！<a href=\"temp.php?ls=normal\"><u>返回</u></a>";
				  if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;
	  
				  echo "<br/><br/>";
			  }else{
				  if($ls_debug) echo "'生成文件".$translateFile."/".$transFile."失败！<br>";
			  }
			}
		else
		{echo "<a href='".$translateFile."/".$transFile."' target='_blank'>".$translateFile."/".$transFile."</a> 已存在， ".($_SESSION['transAll']==0?" 未生成。</br>":" ");}
	
	}else{
		if (is_file ($filename)){ 
			 @unlink ($filename); //若文件已存在，则删除
		}
		//英文网站去除<translate>标签
		$translate_str = $newscontent;
		$p = "%<translate>(.*?)</translate>%si";    //正则表达式
		preg_match_all($p, $newscontent, $arr);
		$temarr = $arr[1];
		
		$source="en";
		$targets = $target;
	
		foreach($temarr as $val){
			$newscontent = str_replace("<translate>".$val."</translate>", $val, $newscontent);
		}
	   $handle   = fopen ($filename,"w"); //打开文件指针，
			/*
			检查文件是否被创建且可写
			 */
		if (!is_writable ($filename)){ 
			if($ls_debug) echo "<script>alert('文件：".$filename."不可写，请检查其属性后重试！');history.go(-1);</script>";
		}
		if (!fwrite ($handle,$newscontent)){  //将信息写入文件
			if($ls_debug) echo "'生成文件".$filename."失败！<br>";
		 } 
		 fclose ($handle); //关闭指针
		 echo "创建<a href='".$filename."'>".$filename."</a>成功！<a href=\"temp.php?ls=normal\"><u>返回</u></a>";
		 if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;

		 echo "<br/><br/>";
	}
	 
	fclose ($fp);
}

/*
------------------------------------------------------
参数：
$filename  //生成文件名
$tagBegin,$tagEnd  //开始和结束标志
$replaceStr  //替换字符串

程序功能：将某文件标签tag 替换成 字符串内容
------------------------------------------------------
*/

function writeTag($filename,$tagBegin,$tagEnd,$replaceStr)
{
	if(!file_exists($filename))
	{
		echo "源文件".$filename."不存在！请设计好后重新生成。</br></br>";
		return;
	}

	
	$fp       = fopen ($filename,"r");
	$content  = fread ($fp,filesize ($filename));
	$len=strlen($content);
	$position1 = strpos ($content,$tagBegin);
	$content1  = substr ($content,0,$position1);	//前半部分
	
	$position2= strpos ($content,$tagEnd);
	$content2  = substr ($content,$position2,($len-$position2));	//后半部分
	$newContent = $content1.$tagBegin.$replaceStr.$content2;
	
	fclose ($fp); //关闭指针	
	
	$handle   = fopen ($filename,"w"); //打开文件指针，创建文件
		  /*
		　检查文件是否被创建且可写
		  */
		
	if (!is_writable ($filename))
	{ 
		echo "<script>alert('文件：".$filename."不可写，请检查其属性后重试！');history.go(-1);</script>";
	}
	if (!fwrite ($handle,$newContent))
	{  //将信息写入文件
		echo "<script>alert('生成文件".$filename."失败！');history.go(-1);</script>";
	} 
	fclose ($handle); //关闭指针
	//echo "创建 <a href='".$filename."'>".$filename."</a>成功！<br /><br />";
}



/*
创建search标签函数
返回标签变量$ls_search
参数 路径 $url
*/
function ls_search($url="")
{
	global $specNames;
    $specificationName=explode(',',$specNames);
	
	$ls_search="<form action='".$url."search.php' name='searchFrom' method='post'>\r\n
            	<input type='hidden' value='allProducts' name='keywords' />\r\n
            	<input type='hidden' value='productName' name='searchItem' />\r\n
			<input type='text' class='inp_srh'  value='Keywords' onclick=\"this.value=''\"  onblur='document.searchFrom.keywords.value=this.value'   />\r\n";
               if(count($specificationName)>0)  //如果有参数，则有下拉参数搜索
			  	{
          		$ls_search.="<select   class='inp_srh_list' name='selectSearchItem' onchange='document.searchFrom.searchItem.value=this.value'  >\r\n
			  	<option value='productName'  'selected'>Name</option>\r\n";
                   
					for($i=0;$i<(count($specificationName));$i++)  //循环处理变量处理 变量名
					{	
					
                    $ls_search.=" <option value='".$specificationName[$i]."'   >".str_replace('Number','No.',str_replace('number','No.',$specificationName[$i]))."</option>\r\n";
                 	 }
			 
					$ls_search.="</select>\r\n";
				 }
            $ls_search.=" <input  class='btn_srh' type='submit'    id='button'   />\r\n
</form>\r\n";

return($ls_search);	
}

/*删除文件夹及文件函数*/

function deldir($dir){
	$dh = opendir($dir);
	while ($file = readdir($dh)){
		if ($file != "." && $file != ".."){
			$fullpath = $dir . "/" . $file;
			if (!is_dir($fullpath)){
				unlink($fullpath);         
			}else{
				deldir($fullpath);
			}
		}
	}
	closedir($dh); 
	if (rmdir($dir)){  
		return true;   
	}else{
		return false;
	}
}

/*查询大类下是否有小类*/

function query_subcate($cateid){
	
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	$midcate_pic_sql="SELECT * FROM `ls_products` WHERE `midcateID`=".$cateid."";
	$midcate_pic_query=$opendb->query($midcate_pic_sql);
	
	while($midcate_pic_rows=mysql_fetch_assoc($midcate_pic_query)){
		$subcate_pic_sql="SELECT * FROM `ls_products` WHERE `subcateID`=".$midcate_pic_rows['ID']."";
		$subcate_pic_query=$opendb->query($subcate_pic_sql);
		
		$subcate_pic_rows=mysql_fetch_assoc($subcate_pic_query);
		if($subcate_pic_rows){
			return true;
		}else{
			return false;
		}
	}
}

//根据产品productID, 查询大类名称
function get_cateName($productID){
	
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	$midcate_pic_sql="SELECT * FROM `ls_products` WHERE ID = ".$productID."";
	$midcate_pic_query=$opendb->query($midcate_pic_sql);
	$midcate_pic_rows=mysql_fetch_assoc($midcate_pic_query);
	
	if($midcate_pic_rows['cateName'] != "" && $midcate_pic_rows['midcateName'] == "" && $midcate_pic_rows['subcateName'] == ""){  //大类
		return $midcate_pic_rows['cateName'];
	}elseif($midcate_pic_rows['cateName'] == "" && $midcate_pic_rows['midcateName'] != "" && $midcate_pic_rows['subcateName'] == ""){  //中类
		
		$subcate_pic_sql="SELECT * FROM `ls_products` WHERE `ID`=".$midcate_pic_rows['midcateID']."";
		$subcate_pic_query=$opendb->query($subcate_pic_sql);
		$subcate_pic_rows=mysql_fetch_assoc($subcate_pic_query);
		
		return $subcate_pic_rows['cateName'];
	}elseif($midcate_pic_rows['cateName'] == "" && $midcate_pic_rows['midcateName'] == "" && $midcate_pic_rows['subcateName'] != ""){  //小类
		
		$subcate_sql="SELECT * FROM `ls_products` WHERE `ID`=".$midcate_pic_rows['subcateID']."";
		$subcate_query=$opendb->query($subcate_sql);
		$subcate_rows=mysql_fetch_assoc($subcate_query);
		
		
		$subcate_pic_sql="SELECT * FROM `ls_products` WHERE `ID`=".$subcate_rows['midcateID']."";
		$subcate_pic_query=$opendb->query($subcate_pic_sql);
		$subcate_pic_rows=mysql_fetch_assoc($subcate_pic_query);
		
		return $subcate_pic_rows['cateName'];
	}

}

//汉字转成拼音字母
function Pinyin($_String, $_Code='gb2312')
{
$_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha".
"|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|".
"cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er".
"|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui".
"|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang".
"|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang".
"|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue".
"|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne".
"|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen".
"|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang".
"|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|".
"she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|".
"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu".
"|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you".
"|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|".
"zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
$_DataValue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990".
"|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725".
"|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263".
"|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003".
"|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697".
"|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211".
"|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922".
"|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468".
"|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664".
"|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407".
"|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959".
"|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652".
"|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369".
"|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128".
"|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914".
"|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645".
"|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149".
"|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087".
"|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658".
"|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340".
"|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888".
"|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585".
"|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847".
"|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055".
"|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780".
"|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274".
"|-10270|-10262|-10260|-10256|-10254";
$_TDataKey = explode('|', $_DataKey);
$_TDataValue = explode('|', $_DataValue);
$_Data = (PHP_VERSION>='5.0') ? array_combine($_TDataKey, $_TDataValue) : _Array_Combine($_TDataKey, $_TDataValue);
arsort($_Data);
reset($_Data);
if($_Code != 'gb2312') $_String = _U2_Utf8_Gb($_String);
$_Res = '';
for($i=0; $i<strlen($_String); $i++)
{
$_P = ord(substr($_String, $i, 1));
if($_P>160) { $_Q = ord(substr($_String, ++$i, 1)); $_P = $_P*256 + $_Q - 65536; }
$_Res .= _Pinyin($_P, $_Data);
}
return preg_replace("/[^a-z0-9]*/", '', $_Res);
}
function _Pinyin($_Num, $_Data)
{
if ($_Num>0 && $_Num<160 ) return chr($_Num);
elseif($_Num<-20319 || $_Num>-10247) return '';
else {
foreach($_Data as $k=>$v){ if($v<=$_Num) break; }
return $k;
}
}
function _U2_Utf8_Gb($_C)
{
$_String = '';
if($_C < 0x80) $_String .= $_C;
elseif($_C < 0x800)
{
$_String .= chr(0xC0 | $_C>>6);
$_String .= chr(0x80 | $_C & 0x3F);
}elseif($_C < 0x10000){
$_String .= chr(0xE0 | $_C>>12);
$_String .= chr(0x80 | $_C>>6 & 0x3F);
$_String .= chr(0x80 | $_C & 0x3F);
} elseif($_C < 0x200000) {
$_String .= chr(0xF0 | $_C>>18);
$_String .= chr(0x80 | $_C>>12 & 0x3F);
$_String .= chr(0x80 | $_C>>6 & 0x3F);
$_String .= chr(0x80 | $_C & 0x3F);
}
return iconv('UTF-8', 'GB2312', $_String);
}
function _Array_Combine($_Arr1, $_Arr2)
{
for($i=0; $i<count($_Arr1); $i++) $_Res[$_Arr1[$i]] = $_Arr2[$i];
return $_Res;
}

/*返回文件扩展名*/

function get_extension ($pic){
	$pics = explode('.' , $pic); 
	$num = count($pics); 
	return strtolower($pics[$num-1]); 
}

function getSubstr($str, $leftStr, $rightStr)
{
 $left = strpos($str, $leftStr);
 //echo '左边:'.$left;
 $right = strpos($str, $rightStr,$left);
 //echo '<br>右边:'.$right;
 if($left < 0 or $right < $left) return '';
 return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr)-1);
}
//搜索页页码函数，$row 总数，$current_page 当前页码，$PageSize 每页条数
function getSearchPages($row, $current_page, $current_page2, $PageSize, $str_list, $filestr){

	$amount = $row;
	$page = $current_page;
	$page2 = $current_page2;
	
	// 记算总共有多少页
	if( $amount ){
	   if( $amount < $PageSize ){ $page_count = 1; }               //如果总数据量小于$PageSize，那么只有一页
	   if( $amount % $PageSize ){                                  //取总数据量除以每页数的余数
		   $page_count = (int)($amount / $PageSize) + 1;           //如果有余数，则页数等于总数据量除以每页数的结果取整再加一
	   }else{
		   $page_count = $amount / $PageSize;                      //如果没有余数，则页数等于总数据量除以每页数的结果
	   }
	}else{
	   $page_count = 0;
	}

	$select_page = "<select name=\"select\" class='select' onChange=\"window.open(this.options[this.selectedIndex].value,'_self')\">";
	for ($i=0; $i< $page_count; $i++){ 

		if($filestr != 'list'){
			$cur = $i+1;
			if($cur != $page){
				$select_page .= "<option value=\""."search_".($i+1)."_".$page2."_".$str_list.".html\">".($i+1)." page</option>";
			}else{
				$select_page .= "<option value=\""."search_".($i+1)."_".$page2."_".$str_list.".html\" selected>".($i+1)." page</option>";
			}
			$a_p = $page_count-$i;
			if($a_p != $page){
	
				$propage.="<div class=\"propage\"><a href=\"search_".($page_count-$i)."_".$page2.'_'.$str_list.".html\">".($page_count-$i)."</a></div>\r\n";
			}else{
	
				$propage.="<div class=\"propage\"><div class=\"current_page\">".($page_count-$i)."</div></div>\r\n";
			}
		}else{
			$cur = $i+1;
			if($cur != $page2){
				$select_page .= "<option value=\""."search_".$page."_".($i+1)."_".$str_list.".html\">".($i+1)." page</option>";
			}else{
				$select_page .= "<option value=\""."search_".$page."_".($i+1)."_".$str_list.".html\" selected>".($i+1)." page</option>";
			}
			$a_p = $page_count-$i;
			if($a_p != $page2){
	
				$propage.="<div class=\"propage\"><a href=\"search_".$page."_".($page_count-$i).'_'.$str_list.".html\">".($page_count-$i)."</a></div>\r\n";
			}else{
	
				$propage.="<div class=\"propage\"><div class=\"current_page\">".($page_count-$i)."</div></div>\r\n";
			}
		}
	}
	$select_page .= "</select>";

	// 翻页链接
	$page_string = '';
	$page_string .= $select_page;
	
	if($filestr != 'list'){
		if( ($page == $page_count) || ($page_count == 0) ){
		   //$page_string .= ' 下一页 | 尾页';
		}else{
			$page_string .= ' <div class="propage"><a href='."search_".$page_count.'_'.$page2.'_'.$str_list.'.html>End</a></div> <div class="propage"><a href='."search_".($page+1).'_'.$page2.'_'.$str_list.'.html>Next</a></div>';
		}
	}else{
		if( ($page2 == $page_count) || ($page_count == 0) ){
		   //$page_string .= ' 下一页 | 尾页';
		}else{
			$page_string .= ' <div class="propage"><a href='."search_".$page.'_'.$page_count.'_'.$str_list.'.html>End</a></div> <div class="propage"><a href='."search_".$page2.'_'.($page+1).'_'.$str_list.'.html>Next</a></div>';
		}
	}
	
	$page_string .= $propage;
	
	if($filestr != 'list'){
		if( $page == 1 ){
		   //$page_string .= '首页 | 上一页 |';
		}else{
			$page_string .= '<div class="propage"><a href=search_'.($page-1).'_'.$page2."_".$str_list.'.html >Previous</a></div> <div class="propage"><a href='."search_1_".$page2.'_'.$str_list.'.html>First</a></div> ';
		}
	}else{
		if( $page2 == 1 ){
		   //$page_string .= '首页 | 上一页 |';
		}else{
			$page_string .= '<div class="propage"><a href=search_'.$page.'_'.($page2-1)."_".$str_list.'.html >Previous</a></div> <div class="propage"><a href='."search_".$page."_1".'_'.$str_list.'.html>First</a></div> ';
		}
	}
	
	if($filestr != 'list'){
		$page_string .= "Total <b>".$amount."</b>, &nbsp; <b>".$PageSize."</b> / Page,";
		$page_string .= " &nbsp; <font color='#FF0000'><b>".$page."</b></font>/<b>".$page_count."</b> Pages";
	}else{
		$page_string .= "Total <b>".$amount."</b>, &nbsp; <b>".$PageSize."</b> / Page,";
		$page_string .= " &nbsp; <font color='#FF0000'><b>".$page2."</b></font>/<b>".$page_count."</b> Pages";
	}

	return $page_string;
}

//得到博客分类列表函数
function get_blog_cate($blog_file){
	
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	
	$news_cate_sql2="select * from `ls_functioncates` where functionName='博客分类' and enable=1 order by Num asc ";

	$result_cate=$opendb->query($news_cate_sql2);
	$num_cate=mysql_num_rows($result_cate);
	$i_news=1;
	
	$blog_path = $blog_file;
	
	$fp	= fopen ($blog_path,"r");
	$blogcontent = fread ($fp,filesize ($blog_path));
	//$blogcontent = str_replace("../","",$blogcontent);
	$bcate = $blogcontent;
	$sort='';
	
	$p = "%<ls_blogcate>(.*?)</ls_blogcate>%si";    //正则表达式
	preg_match_all($p, $bcate, $arr);
	$blogcatearr = $arr[1];
	foreach($blogcatearr as $val){
		$blog22 = "";
		$result_cate2=$opendb->query($news_cate_sql2);
		while($catenews = mysql_fetch_assoc($result_cate2))
		{
			$news_sql2="select * from ls_news where enable=1 and cate='".$catenews['cateName']."' order by Num desc ";
			$suffix_str2=$catenews['suffStr'];
			
			$cate_val = str_replace("{ls_blogtag}",$catenews['cateName'],$val);
			$cate_val = str_replace("{ls_blogmore}","blog".$catenews['suffStr'].".html",$cate_val);
			$p2 = "%<ls_foreach>(.*?)</ls_foreach>%si";    //正则表达式
			preg_match_all($p2, $cate_val, $arr);
			$blogarr = $arr[1][0];

			$blogindex = "";
			
			$news_sql=$news_sql2;
				
			$news_query=$opendb->query($news_sql);
			$blog_i = 0;
			while($news_rows=mysql_fetch_assoc($news_query))
			{
				$blog_i++;
				if(strpos($news_rows['newsText'],'<img') !== false){
					
					$newsImgStr=getStrbyTag("<img ","/>",$news_rows['newsText']);
					$imgHeight=getStrbyTag('height="','" ',$newsImgStr,false);
					$imgWidth=getStrbyTag('width="','" ',$newsImgStr,false);
					$newsImg=getStrbyTag('src="','" ',$newsImgStr);
					$srcImg = getSubstr($newsImg,"src=\"",'"');
					$srcImg = strtolower(getSubstr($newsImg,'src="','"'));  //变小写，清除 src= " 等
					$imgurl = $srcImg;
					$srcImg = str_replace('src=','',$srcImg);
					$srcImg = str_replace('"','',$srcImg);

					$proportion = " width='600' height='370' ";
					$blogimg = $proportion.$newsImg;
				}else{
					$blogimg="src=\"../ls_admin/images/blog.jpg\"";
				}
	
				$blogimg = "<a href=\"blog".$suffix_str2.$news_rows['ID'].".html\"><img ".$blogimg." /></a>";
				$blogtime = $news_rows['newsDate'];
				$blogtitle = "<a href=\"blog".$suffix_str2.$news_rows['ID'].".html\">".$news_rows['newsTitle']."</a>";
				$blogtext = $news_rows['newsTitle'];
				

				$blogindexstr = "";
				
				if($blog_i <= $blog_index_num){
					$blogindexstr = str_replace("{ls_blogimg}",$blogimg,$blogarr);
					$blogindexstr = str_replace("{ls_blogtime}",$blogtime,$blogindexstr);
					$blogindexstr = str_replace("{ls_blogtitle}",$blogtitle,$blogindexstr);
					$blogindexstr = str_replace("{ls_blogtext}",$blogtext,$blogindexstr);
					
					$blogindex .= $blogindexstr;
				}
			}
			$blog123 = str_replace("<ls_foreach>".$blogarr."</ls_foreach>", $blogindex, $cate_val);
			$blog22 .= $blog123;
	  	}
	  	//$blogcontent = str_replace("<ls_blogcate>".$val."</ls_blogcate>", $blog22, $blogcontent);
		$blogcontent = $blog22;
	}
	return $blogcontent;
}

//返回大类名称以及对应大类链接，如大类下有小类链接到大类下第一个小类上
function get_pro_cate($id){
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	$p_cate_sql="select * from ls_products where midcateName 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";
	$p_cate_query=$opendb->query($p_cate_sql);
	//$s_p_cate="\n <div class=\"cate_list\">\n"; //大类菜单样式，div css:cate_list
	$p_num=mysql_num_rows($p_cate_query);
	
	$s_p_cate="";
	$x = $p_num;
	$y = 0;
	while($p_cate_rows=mysql_fetch_assoc($p_cate_query))
	{
	  $y++;
	  $p_midcate_sql="select * from ls_products where cateName 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 and midcateID=".$p_cate_rows['ID']." order by Num asc";
	  $p_midcate_query=$opendb->query($p_midcate_sql);
	  $p_midcate_num=mysql_num_rows($p_midcate_query);
	  $rows2=mysql_fetch_assoc($p_midcate_query);
	  
	  if($p_midcate_num==0)//大类
	  {

		  $s_p_cate.="<li><a href='../".$p_cate_rows['cateFolders']."/".$p_cate_rows['cateFolders'].".html'> ".$p_cate_rows['cateName']."</a></li>";
		// $s_p_cate.="\n <div class=\"cate_list\">\n"; //大类菜单样式，div css:cate_list
	  } 
	  else//大类中类
	  {
		//$s_p_cate.="&nbsp;<img src='../Templates/".$templates_var."/images/cate.gif' border='0'> \n";  //大类引导图
		$detailsfile="../".$p_cate_rows['cateFolders']."/".$p_cate_rows['cateFolders'].".html";
		$detailsfile2="../".$templates_var."1/catedetail.html";
		if(file_exists($detailsfile2))
		{$s_p_cate.="\n<li><a href='".$detailsfile."'> ".$p_cate_rows['cateName']."</a><ul>";}
		else
		{
			$s_p_cate.="\n<li><a href='../".$p_cate_rows['cateFolders']."/".$rows2['midcateFolders']."/".$rows2['midcateFolders'].".html' onclick=\"turnit(".$p_cate_rows['ID'].",".$p_cate_rows['ID'].");this.href=this.href+'?menuId='+".$p_cate_rows['ID']."+'&cate='+".$p_cate_rows['ID'].";\" > ".$p_cate_rows['cateName']."</a></li>";
		}
	  }//if($p_midcate_num==0)//dalei
	
	}
	$s_p_cate.="";
	//echo $s_p_cate;
	$s_p1_cate=str_replace("../","",$s_p_cate);//cate
	$s_p2_cate=str_replace("../","../",$s_p_cate);//pro2_cate
	$s_p3_cate=str_replace("../","../../",$s_p_cate);//pro3_cate
	$s_p4_cate=str_replace("../","../../../",$s_p_cate);//pro4_cate
	if($id == 0){
		return $s_p1_cate;
	}elseif($id == 1){
		return $s_p_cate;
	}elseif($id == 2){
		return $s_p2_cate;
	}elseif($id == 3){
		return $s_p3_cate;
	}elseif($id == 4){
		return $s_p4_cate;
	}

}

// 获得某类下第一个产品的记录 for get_allcatepics
function get_product_class_rows($classpro_rowsID)
{
	require_once('inc/conn.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');

	$product_class_sql="select * from ls_products where branchID=0 and productID=".$classpro_rowsID." and AdditionalAttributesClassPro&1   order by Num ASC";	//定义 AdditionalAttributesClassPro 属性
	$product_class_query=$opendb->query($product_class_sql);
	$product_class_num=mysql_num_rows($product_class_query);
	if($product_class_num>=1) //已定义classpro 展示产品
	{
		$product_class_rows=mysql_fetch_assoc($product_class_query);
	}
	else  //未定义classpro 展示产品，直接选一个
	{
		$product_class_sql="select * from ls_products where  branchID=0 and productID=".$classpro_rowsID." and enable=1  order by ID desc";
		$product_class_query=$opendb->query($product_class_sql);
		$product_class_num=mysql_num_rows($product_class_query);
		if($product_class_num>=1) //已定义classpro 展示产品
		{
			$product_class_rows=mysql_fetch_assoc($product_class_query);
		}
	}
	return $product_class_rows;
}
	
// 获得某类下所有产品的图片及连接
function get_product_cate_pics($catepics_rowsID,$thisfolder)
{
	$s_catepics="";
	require_once('inc/conn.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	global $ls_catepicsPicW;

	$catepics_sql="select * from ls_products where branchID=0 and  productID=".$catepics_rowsID." and enable=1  order by ID desc";
	$catepics_query=$opendb->query($catepics_sql);
	$catepics_num=mysql_num_rows($catepics_query);
	if($catepics_num>=1) //已定义catepics 展示产品
	{
		while($catepics_rows=mysql_fetch_assoc($catepics_query))
		{
			$catepics_piclink=getpiclink($catepics_rows['ID'],$catepics_rows['productPic']); //
			//echo $catepics_rows['ID']."--".$catepics_piclink['picsrc']; // /thumbnails/1361107436.jpg  带/

			$s_catepics.="<li class=\"class_dt\"><a href=\"../".$thisfolder.$catepics_piclink['piclink']."\"><img src='../".$thisfolder.$catepics_piclink['picsrc']."' width='".$ls_catepicsPicW."' border='0'></a> </li> \r\n";	//每类产品一行
			//echo $s_catepics;
			
		}
	}
	else
	{
		//$s_catepics="No products in cate ".$catepics_rowsID;
	}

return $s_catepics;
}

//后台编辑器中的内链与图片转换成相对路径
function editorPath($urlPath, $specification){
	if(strpos($urlPath, "/ls_admin") == 0){
		return str_replace("src=\"/ls_admin", "src=\"../ls_admin", $specification);
	}else{
		return str_replace(substr($urlPath, 0, strpos($urlPath, "/ls_admin")), "..", $specification);
	}
}

// get_catepics 首页多类产品列表，每类一行图片
function get_allcatepics()
{
		require_once('inc/conn.php');
		$opendb=new mydb();
		require_once('inc/char_set.php');
		$s_catepics="";
		$catepics_sql="select * from ls_products where branchID=0 and midcateName 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";
		$catepics_query=$opendb->query($catepics_sql);
		//$s_catepics="\n <div class=\"cate_list\">\n"; //大类菜单样式，div css:cate_list
		$s_catepics.="<ul class=\"catepics_list\">";
		while($catepics_rows=mysql_fetch_assoc($catepics_query))
		{
		  $pro_midcate_sql="select * from ls_products where branchID=0 and cateName 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 and midcateID=".$catepics_rows['ID']." order by Num asc";
		  $pro_midcate_query=$opendb->query($pro_midcate_sql);
		  $pro_midcate_num=mysql_num_rows($pro_midcate_query);
	  
		  if($pro_midcate_num==0)//大类
		  {
			if($catepics_rows['ID']=="")continue; //没有跳过循环
			$s_catepics.=get_product_cate_pics($catepics_rows['ID'],$catepics_rows['cateFolders']).$catepics_rows['cateName'];
		  } 
		  else//大类中类
		  {
			//$s_catepics.="&nbsp;<img src='../Templates/".$templates_var."/images/cate.gif' border='0'> \n";  //大类引导图
			$detailsfile="../".$catepics_rows['cateFolders']."/indexdetails.html";
			if(file_exists($detailsfile))
			{$s_catepics.=" <dt><a href='".$detailsfile."'>".$catepics_rows['cateName']."</a></dt>\r\n";}
			else
			{
				//$s_catepics.="<li id=\"catepics_list_li_title\"> <strong>".$catepics_rows['cateName']."</strong></li> \r\n";	
			}

		
			while($pro_midcate_rows=mysql_fetch_assoc($pro_midcate_query))
			{
				$pro_subcate_sql="select * from ls_products where branchID=0 and midcateName 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 and subcateID=".$pro_midcate_rows['ID']." order by Num asc";
				$pro_subcate_query=$opendb->query($pro_subcate_sql);
				$pro_subcate_num=mysql_num_rows($pro_subcate_query); 

				//$s_catepics.="<div class=\"midcate_list\">"; //中类菜单样式
	
				if($pro_subcate_num==0)//没小类
				{
					if($pro_midcate_rows['ID']=="")continue; //没有跳过循环
					$s_catepics.=get_product_cate_pics($pro_midcate_rows['ID'],$catepics_rows['cateFolders']."/".$pro_midcate_rows['midcateFolders']).$pro_midcate_rows['midcateName']; //$catepics_rows['cateName'].$pro_midcate_rows['midcateName']
				}
				else//有小类
				{
					//$s_catepics.="&nbsp;<img src='../Templates/".$templates_var."/images/midcate.gif' border='0'> \n"; //中类引导图
					$detailsfile="../".$catepics_rows['cateFolders']."/".$pro_midcate_rows['midcateName']."/indexdetails.html";
					if(file_exists($detailsfile))
					{$s_catepics.="<a href='".$detailsfile."'>".$pro_midcate_rows['midcateName']."</a>\r\n";}
					else
					{
						//$s_catepics.="<li id=\"catepics_list_li_title\">  <strong>".$pro_midcate_rows['midcateName']."</strong></li> \r\n";			
					}
					//$s_catepics.="<div class=\"subcate_list\">";//小类菜单样式
					while($pro_subcate_rows=mysql_fetch_assoc($pro_subcate_query))		//小类生成
					{
						if($pro_subcate_rows['ID']=="")continue; //没有跳过循环
						$s_catepics.=get_product_cate_pics($pro_subcate_rows['ID'],$catepics_rows['cateFolders']."/".$pro_midcate_rows['midcateFolders']."/".$pro_subcate_rows['subcateFolders']).$pro_subcate_rows['subcateName']; //$catepics_rows['cateName'].$pro_midcate_rows['midcateName'].$pro_subcate_rows['subcateName']
					}
					$s_catepics.=" \n\r\n"; 
				} 
			} //while($pro_midcate_rows=mysql_fetch_assoc($pro_midcate_query))
			$s_catepics.="  \r\n";
		  }//if($pro_midcate_num==0)//大类
		}
	$s_catepics.="</ul>\r\n ";
	$allcatepics=str_replace("../","",$s_catepics);//cate

	//$allcatepics=$s_catepics;
	return $allcatepics;
}

function ifNeedTrans($filename,$translate,$gallaryPage=false)
{
	$ifTrans=1; //1 代表需要翻译，需要覆盖
	If(file_exists($filename))
	{
		$fp = fopen ($filename,"r");
		$content = fread ($fp,filesize ($filename));  //
		$simuFlag="<font color='#F00'>".$translate."</font>"; //模拟翻译标志
		//if(strpos($content,$simuFlag)===false) $ifTrans=0;
		if(filesize ($filename)>1) $ifTrans=0;  //模拟翻译不覆盖
		
	}
	else
	{	
		if($gallaryPage)$_SESSION['lastBlankFile']=$filename;  //记录上一个为空的相册页文件，为产品相册页2次写入
	}
	return $ifTrans;	
}
function translateApp($newscontent,$filename,$target="zh-CN"){
	
	global $count_num,$translate_key,$simuTransLow,$mutiLangDomianFlag;  //constant
 
	$api_key =$translate_key ;

	 
	$newscontent = str_replace("<img src=\"../../../", "<img src=\"", $newscontent);
	$newscontent = str_replace("<img src='../../../", "<img src='", $newscontent);
	$newscontent = str_replace("css\" href=\"../../../", "css\" href=\"", $newscontent);
	$newscontent = str_replace("css\" href='../../../", "css\" href='", $newscontent);
	$newscontent = str_replace("javascript\" src=\"../../../", "javascript\" src=\"", $newscontent);
	$newscontent = str_replace("javascript\" src='../../../", "javascript\" src='", $newscontent);
	$newscontent = str_replace("<img src=\"../../", "<img src=\"", $newscontent);
	$newscontent = str_replace("<img src='../../", "<img src='", $newscontent);
	$newscontent = str_replace("css\" href=\"../../", "css\" href=\"", $newscontent);
	$newscontent = str_replace("css\" href='../../", "css\" href='", $newscontent);
	$newscontent = str_replace("javascript\" src=\"../../", "javascript\" src=\"", $newscontent);
	$newscontent = str_replace("javascript\" src='../../", "javascript\" src='", $newscontent);
	$newscontent = str_replace("<img src=\"../", "<img src=\"", $newscontent);
	$newscontent = str_replace("<img src='../", "<img src='", $newscontent);
	$newscontent = str_replace("css\" href=\"../", "css\" href=\"", $newscontent);
	$newscontent = str_replace("css\" href='../", "css\" href='", $newscontent);
	$newscontent = str_replace("javascript\" src=\"../", "javascript\" src=\"", $newscontent);
	$newscontent = str_replace("javascript\" src='../", "javascript\" src='", $newscontent);
	
	$newscontent = str_replace("<img src=\"", "<img src=\"".$mutiLangDomianFlag, $newscontent);  //双引号的图片
	$newscontent = str_replace("<img src='", "<img src='".$mutiLangDomianFlag, $newscontent);  //单引号的图片
	
	$newscontent = str_replace("css\" href=\"", "css\" href=\"".$mutiLangDomianFlag, $newscontent);  //双引号的样式
	$newscontent = str_replace("css\" href='", "css\" href='".$mutiLangDomianFlag, $newscontent);  //单引号的样式
	
	$newscontent = str_replace("javascript\" src=\"", "javascript\" src=\"".$mutiLangDomianFlag, $newscontent);  //双引号的样式
	$newscontent = str_replace("javascript\" src='", "javascript\" src='".$mutiLangDomianFlag, $newscontent);  //单引号的样式

	           
	$translate_str = $newscontent;
	$p = "%<translate>(.*?)</translate>%si";    //正则表达式
	preg_match_all($p, $newscontent, $arr);
	$temarr = $arr[1];
	//var_dump(count($temarr));exit;
	$source="en";
	$targets = $target;
						//echo $api_key."===".$out_val."===".$target."===".$source;
						//exit;

	foreach($temarr as $val){
		if(strlen($val)>1000){
			
			//如果翻译的内容大于1000，则进行分段
			foreach(subpart($val, 1000, "utf-8") as $out_val){
				//$count_num ++;
				//echo "<h4 style='color:#00F'>".$count_num."</h4>";
				$_SESSION['transTotal']+=strlen($out_val);
				$obj = translate($api_key,$out_val,$target,$source);
				
				if($obj != null)
				{
					
					if(isset($obj['error']))
					{
						
						echo "Error is : ".$obj['error']['message'];

					}
					else
					{
						//echo $obj['data']['translations'][0]['translatedText']." ";
						$translate_val = $obj['data']['translations'][0]['translatedText']."";
						
						
						$translate_str = str_replace($out_val, $translate_val, $translate_str);
						
						if(isset($obj['data']['translations'][0]['detectedSourceLanguage'])) //this is set if only source is not available.
							echo "Detecte Source Languge : ".$obj['data']['translations'][0]['detectedSourceLanguage']." ";
					}
				}
				else
					echo "Error ";
			}
		}else{
			//$count_num ++;
			//echo "<h4 style='color:#00F'>".$count_num."</h4>";
				$_SESSION['transTotal']+=strlen($val);
				$obj = translate($api_key,$val,$target,$source);
				
			if($obj != null)
			{
				
				if(isset($obj['error']))
				{
					
					echo "Error is : ".$obj['error']['message'];
				}
				else
				{
					
					//echo $obj['data']['translations'][0]['translatedText']." ";
					$translate_val = $obj['data']['translations'][0]['translatedText']."";
					//var_dump($translate_val);echo "<br/>";
					$translate_str = str_replace("<translate>".$val."</translate>", $translate_val, $translate_str);
					//$translate_str = str_replace("<translate>".$val."</translate>", $val."<font color='#F00'>".$target."</font>", $translate_str);
						//if(isset($obj['data']['translations'][0]['detectedSourceLanguage'])) //this is set if only source is not available.
						//echo "Detecte Source Languge : ".$obj['data']['translations'][0]['detectedSourceLanguage']." ";
				}
			}
			else
			
				echo "Error ";
		}
		
	}
	//var_dump($translate_str);exit;
	//$filename="demo2.html";  //目标路径
	if (is_file ($filename)){
		 @unlink ($filename); //若文件已存在，则删除
	}
	$handle = fopen ($filename,"w"); //打开文件指针，
		//检查文件是否被创建且可写 
	if(!is_writable ($filename)){ 
		 echo "<script>alert('文件：".$filename."不可写，请检查其属性后重试！');history.go(-1);</script>";
	}

	if(!fwrite ($handle,$translate_str)){  //将信息写入文件
		return false;
	}else{
		return true;
		echo $filename."  ok, 已翻译".$_SESSION['transTotal']."字符  ";
		 ob_flush();
		flush();
 
	}
	fclose($handle);
}
//GOOGLE 翻译基础功能，模拟翻译
function translate($api_key,$text,$target,$source=false)
{
		global   $simuTransLow,$flagFastSlow,$simuTransCons;
		$_SESSION['simuTrans']=$simuTransCons;
	 	 //  constant $simuTransLow,$flagFastSlow; $simuTransLow低级模拟翻译 ~fr~ 分割，ls_syscode, function translat
		 
		 // $flagFastSlow; 小于这个字符数，加入快表，ls_syscode, function translat

		//sleep(2); //耗时的处理过程 100秒100K，1000次
		$_SESSION['transTimes']+=1; //本轮请求次数加1
		$thisTransSecond=getmicrotime()-$_SESSION['transStart']; //本轮持续秒数
		$thisTransTimes=$_SESSION['transTimes']; //本轮持续次数数
		$thisTansBytes=$_SESSION['transTotal']-$_SESSION['thisTotalStart']; //本轮持续字节数
		$sleepSecond=6; //延迟秒数
		

		//持续大于80秒,减去延迟时间，看次数，字节数插入耗时
		$thisTransSecondCompens=$thisTransSecond-$_SESSION['delayTimes']*$sleepSecond;
		$thisTansBytesCompens=$thisTansBytes-$_SESSION['delayTimes']*$sleepSecond*800;
		$thisTransTimesCompens=$thisTransTimes-$_SESSION['delayTimes']*$sleepSecond*8;
		
		//不是模拟翻译延迟
		if($_SESSION['simuTrans']!=1 && $thisTransSecondCompens <=60 && ($thisTansBytesCompens>65000||$thisTransTimesCompens>200))
		{
			echo "<br/>本轮翻译持续".round($thisTransSecond,1)."秒，本轮翻译".$thisTansBytes."字节，请求次数".$thisTransTimes."，暂停".$sleepSecond."秒<br/>";
			sleep($sleepSecond);
			$_SESSION['delayTimes']+=1;
		}


	  if($_SESSION['simuTrans']==1)  //如果是模拟翻译
	  {
		  $obj['data']['translations'][0]['translatedText']=$text."<font color='#F00'>".$target."</font>";
		   
	  }
	  else
	  {
			//$url = 'https://www.googleapis.com/language/translate/v2?key=' . $api_key . '&q=' . rawurlencode($text);//translation神经网络（NMT）翻译，www词组翻译
			$transFastStr=transfast($text,$target); //查快表，词组表
			if(!$transFastStr)
			{
				
				$transSlowStr=transslow($text,$target); //查慢表，标题文章表
				if(!$transSlowStr)
				{
					
					$url = 'https://translation.googleapis.com/language/translate/v2?key=' . $api_key . '&q=' . rawurlencode($text);
					$url .= '&target='.$target;
					if($source)
					$url .= '&source='.$source;
					if(!$simuTransLow) //低级模拟翻译
					{
						//echo $url."<br/><br/>";

						$ch = curl_init($url);
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
						curl_setopt($ch, CURLOPT_TIMEOUT,1200);
						$response = curl_exec($ch);
						curl_close($ch);
						$obj =json_decode($response,true); //true converts stdClass to associative array.
						if(strlen($text)<$flagFastSlow) //增加快表内容
						{addtransfast($text,$target,$obj['data']['translations'][0]['translatedText'],"menu");}
						else
						{addtransslow($text,$target,$obj['data']['translations'][0]['translatedText'],"menu");}
					}
					else
					{
						
						$obj['data']['translations'][0]['translatedText']=$text."~".$target."~";
					}
						//var_dump($obj);exit;
				}
				else
				{
					
					 $obj['data']['translations'][0]['translatedText']=$transSlowStr;
				}
			}
			else
			{
				
				 $obj['data']['translations'][0]['translatedText']=$transFastStr;
			}
	}	
		//echo "<br/>本轮翻译持续".$thisTansTime."秒，本轮翻译".$thisTansBytes."字节，请求次数".$_SESSION['transTimes']."，<br/>";
		return $obj;
}
/*
------------------------------------------------------
参数：
$text  //翻译文本
$target  //目标语言
$source  //源语言

程序功能：查询快表：单词短语翻译表，常用单词信息表
------------------------------------------------------
*/

function transfast($text,$target,$source=false)
{
    $text=htmlspecialchars($text, ENT_QUOTES); //处理html定界符和引号
	require_once('inc/conn.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	$trans_sql="select * from ls_transfast where en='".$text."' ";
 
	$trans_query=$opendb->query($trans_sql);
	$transNum=mysql_num_rows($trans_query);
	$trans_rows=mysql_fetch_assoc($trans_query);
	$transText=($trans_rows[$target]==""?false:htmlspecialchars_decode($trans_rows[$target], ENT_QUOTES));
	
	if($transNum!=0)
	{
		$trans_sql="update ls_transfast set queryTotal=queryTotal+1 where ID=".$trans_rows['ID']." ";
		$trans_query=$opendb->query($trans_sql); //查询计数增加
	}
	
	If($transText){
		$_SESSION['transfast']+=1;  //快表条数
		$_SESSION['transfastTotal']+=($transText?strlen($transText):0);  //快表字数
	}
	
	
	return $transText;

}

/*
------------------------------------------------------
参数：
$text  //翻译源文本
$target  //目标语言
$transtr  //翻译结果

程序功能：新增快表项目：单词短语翻译对
------------------------------------------------------
*/

function addtransfast($text,$target,$transtr,$cate="menu")
{
    $text=htmlspecialchars($text, ENT_QUOTES); //处理html定界符和引号
    $transtr=htmlspecialchars($transtr, ENT_QUOTES); //处理html定界符和引号
	require_once('inc/conn.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
 
	$trans_sql="select * from ls_transfast where en='".$text."' ";
	$trans_query=$opendb->query($trans_sql);
	$transNum=mysql_num_rows($trans_query);
	$trans_rows=mysql_fetch_assoc($trans_query);
	$transResult=false;
	
	
	if($transNum==0)
	{
		$trans_sql="insert into ls_transfast   (en,".$target.",cate) value ('".$text."','".$transtr."','".$cate."' ) ";
		$trans_query=$opendb->query($trans_sql); //增加新的翻译内容
		if($trans_query) $transResult=true;
	}
	else
	{
		$trans_sql="update ls_transfast  set ".$target."='".$transtr."',cate='".$cate."' where ID=".$trans_rows['ID']." ";
		$trans_query=$opendb->query($trans_sql); //增加、更新新的语种
		if($trans_query) $transResult=true;
	}
	return $transResult;

}

/*
------------------------------------------------------
参数：
$text  //翻译文本
$target  //目标语言
$source  //源语言
$enTableName  //对应英文表名
$enID  //en原表 ID号
$enField  //en原表 字段

程序功能：查询慢表翻译，本站长句翻译信息对照表
------------------------------------------------------
*/

function transslow($text,$target,$enTableName="",$enID="",$enField="",$source=false)
{
    $text=htmlspecialchars($text, ENT_QUOTES); //处理html定界符和引号
	require_once('inc/conn.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	$trans_sql="select * from ls_transslow where en='".$text."' ";
	$trans_query=$opendb->query($trans_sql);
	$transNum=mysql_num_rows($trans_query);
	$trans_rows=mysql_fetch_assoc($trans_query);
	$transText=($trans_rows[$target]==""?false:htmlspecialchars_decode($trans_rows[$target], ENT_QUOTES));
	
	if($transNum!=0)
	{
		$trans_sql="update ls_transslow set queryTotal=queryTotal+1 where ID=".$trans_rows['ID']." ";
		$trans_query=$opendb->query($trans_sql); //查询计数增加
	}
	
	If($transText){
		$_SESSION['transslow']+=1;  //慢表条数
		$_SESSION['transslowTotal']+=($transText?strlen($transText):0);  //慢表字数 
	}

	return $transText;


}

/*
------------------------------------------------------
参数：
$text  //翻译源文本
$target  //目标语言
$transtr  //翻译结果

程序功能：新增慢表项，本站长句翻译信息对照表
------------------------------------------------------
*/

function addtransslow($text,$target,$transtr,$cate="menu")
{
    $text=htmlspecialchars($text, ENT_QUOTES); //处理html定界符和引号
    $transtr=htmlspecialchars($transtr, ENT_QUOTES); //处理html定界符和引号
	require_once('inc/conn.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	$trans_sql="select * from ls_transslow where en='".$text."' ";
	$trans_query=$opendb->query($trans_sql);
	$transNum=mysql_num_rows($trans_query);
	$trans_rows=mysql_fetch_assoc($trans_query);
	$transResult=false;
	
	if($transNum==0)
	{
		$trans_sql="insert into ls_transslow   (en,".$target.",cate) value ('".$text."','".$transtr."','".$cate."' ) ";
		$trans_query=$opendb->query($trans_sql); //增加翻译结果
		if($trans_query) $transResult=true;
	}
	else
	{
		$trans_sql="update ls_transslow  set ".$target."='".$transtr."',cate='".$cate."' where ID=".$trans_rows['ID']." ";
		$trans_query=$opendb->query($trans_sql); //增加、更新新的语种
		if($trans_query) $transResult=true;
	}
	return $transResult;

}

//英文文章分段，分隔时可以截取完整单词与<>符号的标签，翻译函数中用到
function subpart($cont, $len, $charset){
	$end = 0;
	$contlen = strlen($cont);
	//echo $contlen."<br />";   //总长度
	for ($i=0; $i<=$contlen;){
		//echo "起始的位置".$i."&nbsp;";  //起始的位置
		$end = strrpos(substr($cont, 0, $end+$len), " ");
		//echo "结束的位置".$end."&nbsp;";    //结束的位置
		
		$lt = strrpos(substr($cont, 0, $end), "<");
		$gt = strrpos(substr($cont, 0, $end), ">");
		
		if($lt > $gt){
			$end = strrpos(substr($cont, 0, $end), "<");
			//echo "最终结束的位置：".$end."&nbsp;"; 
		}
		//echo "小号数量：".$lt."&nbsp;";
		//echo "大号数量：".$gt."&nbsp";
		$len_num = $end - $i;
		//echo "截取的长度".$len_num."<br />";   //截取的长度

		$contarr[] = substr($cont, $i, $len_num);
		$i = $end;
		if($end+$len > $contlen){ break;}
	}
	$contarr[] = substr($cont, $i, $len);
	return $contarr;
}

//二维数组中查询查值，返回 查到的一维数组  翻译系统用到
function deep_in_array($value, $array) {
	$cars = array();
	foreach($array as $k=>$val){
		if($val['translate_name'] == $value){
			$cars = $val;
			return $cars;
		}
	}
	return $cars;
}

//记录代码运行时间  
function getmicrotime()
{
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}

/*
* ============================== 截取含有 html标签的字符串 =========================
* @param (string) $str   待截取字符串
* @param (int)  $lenth  截取长度
* @param (string) $repalce 超出的内容用$repalce替换之（该参数可以为带有html标签的字符串）
* @param (string) $anchor 截取锚点，如果截取过程中遇到这个标记锚点就截至该锚点处
* @return (string) $result 返回值
* @demo  $res = cut_html_str($str, 256, '...'); //截取256个长度，其余部分用'...'替换
* ===============================================================================
*/
function cut_html_str($str, $lenth, $replace='', $anchor='<!-- break -->'){ 
    $_lenth = mb_strlen($str, "utf-8"); // 统计字符串长度（中、英文都算一个字符）
    if($_lenth <= $lenth){
        return $str;    // 传入的字符串长度小于截取长度，原样返回
    }
    $strlen_var = strlen($str);     // 统计字符串长度（UTF8编码下-中文算3个字符，英文算一个字符）
    if(strpos($str, '<') === false){ 
        return mb_substr($str, 0, $lenth);  // 不包含 html 标签 ，直接截取
    } 
    if($e = strpos($str, $anchor)){ 
        return mb_substr($str, 0, $e);  // 包含截断标志，优先
    } 
    $html_tag = 0;  // html 代码标记 
    $result = '';   // 摘要字符串
    $html_array = array('left' => array(), 'right' => array()); //记录截取后字符串内出现的 html 标签，开始=>left,结束=>right
    /*
    * 如字符串为：<h3><p><b>a</b></h3>，假设p未闭合，数组则为：array('left'=>array('h3','p','b'), 'right'=>'b','h3');
    * 仅补全 html 标签，<? <% 等其它语言标记，会产生不可预知结果
    */
    for($i = 0; $i < $strlen_var; ++$i) { 
        if(!$lenth) break;  // 遍历完之后跳出
        $current_var = substr($str, $i, 1); // 当前字符
        if($current_var == '<'){ // html 代码开始 
            $html_tag = 1; 
            $html_array_str = ''; 
        }else if($html_tag == 1){ // 一段 html 代码结束 
            if($current_var == '>'){ 
                $html_array_str = trim($html_array_str); //去除首尾空格，如 <br / > < img src="" / > 等可能出现首尾空格
                if(substr($html_array_str, -1) != '/'){ //判断最后一个字符是否为 /，若是，则标签已闭合，不记录
                    // 判断第一个字符是否 /，若是，则放在 right 单元 
                    $f = substr($html_array_str, 0, 1); 
                    if($f == '/'){ 
                        $html_array['right'][] = str_replace('/', '', $html_array_str); // 去掉 '/' 
                    }else if($f != '?'){ // 若是?，则为 PHP 代码，跳过
                        // 若有半角空格，以空格分割，第一个单元为 html 标签。如：<h2 class="a"> <p class="a"> 
                        if(strpos($html_array_str, ' ') !== false){ 
                        // 分割成2个单元，可能有多个空格，如：<h2 class="" id=""> 
                        $html_array['left'][] = strtolower(current(explode(' ', $html_array_str, 2))); 
                        }else{ 
                        //若没有空格，整个字符串为 html 标签，如：<b> <p> 等，统一转换为小写
                        $html_array['left'][] = strtolower($html_array_str); 
                        } 
                    } 
                } 
                $html_array_str = ''; // 字符串重置
                $html_tag = 0; 
            }else{ 
                $html_array_str .= $current_var; //将< >之间的字符组成一个字符串,用于提取 html 标签
            } 
        }else{ 
            --$lenth; // 非 html 代码才记数
        } 
        $ord_var_c = ord($str{$i}); 
        switch (true) { 
            case (($ord_var_c & 0xE0) == 0xC0): // 2 字节 
                $result .= substr($str, $i, 2); 
                $i += 1; break; 
            case (($ord_var_c & 0xF0) == 0xE0): // 3 字节
                $result .= substr($str, $i, 3); 
                $i += 2; break; 
            case (($ord_var_c & 0xF8) == 0xF0): // 4 字节
                $result .= substr($str, $i, 4); 
                $i += 3; break; 
            case (($ord_var_c & 0xFC) == 0xF8): // 5 字节 
                $result .= substr($str, $i, 5); 
                $i += 4; break; 
            case (($ord_var_c & 0xFE) == 0xFC): // 6 字节
                $result .= substr($str, $i, 6); 
                $i += 5; break; 
            default: // 1 字节 
                $result .= $current_var; 
        } 
    } 
    if($html_array['left']){ //比对左右 html 标签，不足则补全
        $html_array['left'] = array_reverse($html_array['left']); //翻转left数组，补充的顺序应与 html 出现的顺序相反
        foreach($html_array['left'] as $index => $tag){ 
            $key = array_search($tag, $html_array['right']); // 判断该标签是否出现在 right 中
            if($key !== false){ // 出现，从 right 中删除该单元
                unset($html_array['right'][$key]); 
            }else{ // 没有出现，需要补全 
                $result .= '</'.$tag.'>'; 
            } 
        } 
    } 
    return $result.$replace; 
}

/** 
*对内容中的关键词添加链接 
*只处理第一次出现的关键词，对已有链接的关键不会再加链接，支持中英文 
*$content:string 原字符串 
*$keyword:string  关键词 
*$link:string,链接 
*/ 
function internal_keyword_link($content,$keyword,$link){
    //排除图片中的关键词 
    $content = preg_replace( '|(<img[^>]*?)('.$keyword.')([^>]*?>)|U', '$1%&&&&&%$3', $content);
	if(preg_match("/[\x7f-\xff]/", $keyword)){
		$regEx = '/(?!((<.*?)|(<a.*?)))('.$keyword.')(?!(([^<>]*?)>)|([^>]*?<\/a>))/si';
	}else{
		$regEx = '/(?!((<.*?)|(<a.*?)))(\b'.$keyword.'\b)(?!(([^<>]*?)>)|([^>]*?<\/a>))/si';
	}
	//$link = str_replace('../','',$link);
    $url="<a href='".$link."' class=\"internal\">".$keyword."</a>";  //添加带有internal标记的内链
    $content = preg_replace($regEx,$url,$content,-1);
    //还原图片中的关键词
    $content=str_replace('%&&&&&%',$keyword,$content);
	
    return $content;
}

/*对原来有内链关键词去掉链接*/
function clear_keyword_link($content,$keyword){
	//$regEx = '~<a.*?class="internal"[\s\S]*?</a>~';  //去掉带有internal标记的内链
    $regEx = '/<a[^>]+>('.$keyword.')[^>]+a>/';
    $content = preg_replace($regEx,$keyword,$content,-1);
    return $content;
}

/**
 * 十六进制颜色 转 RGB
 */
function rgbToHex($hexColor) {
	$color = str_replace('#', '', $hexColor);
	if (strlen($color) > 3) {
		$rgb = array(
			'r' => hexdec(substr($color, 0, 2)),
			'g' => hexdec(substr($color, 2, 2)),
			'b' => hexdec(substr($color, 4, 2))
		);
	} else {
		$color = $hexColor;
		$r = substr($color, 0, 1) . substr($color, 0, 1);
		$g = substr($color, 1, 1) . substr($color, 1, 1);
		$b = substr($color, 2, 1) . substr($color, 2, 1);
		$rgb = array(
			'r' => hexdec($r),
			'g' => hexdec($g),
			'b' => hexdec($b)
		);
	}
	return $rgb;
}

/* 
//正则图片添加alt,title 标记
function addAltTitle($alt,$title,$str){
	$preg = "/<img.*?src=[\"|\'](.*?)[\"|\'].*?>/";
	$img = '<img src="$1" alt="'.$alt.'"title="'.$title.'">';

	
	return preg_replace($preg,$img,$str);

}
 
*/

//正则图片添加alt,title 标记
function addAltTitle($alt,$title,$str){
	 
	 $_SESSION['alt111']=$alt;
	 $_SESSION['title111']=$title;

 
    return preg_replace_callback( "/(<img.*?src=[\"|\'].*?[\"|\'].*?>)/",'callbackAddAltTitle',$str);
 

}

//addAltTitle 正则替换函数的 回调函数
function callbackAddAltTitle( $str1){
		 
	$str2=$str1[1];
	
		
	$alt111=$_SESSION['alt111'];
	$title111=$_SESSION['title111'];

	

	 if(!preg_match ("/alt=[\"|\']/",$str2))
	 {$str2 =	str_replace("/>", 'alt="'.$alt111.'" />',$str2);}
	 else
	 {$str2 =	preg_replace("/alt=[\"|\']s*[\"|\']/", 'alt="'.$alt111.'"',$str2);}

	  if(!preg_match ("/title=[\"|\']/",$str2))

	 {$str2 =	str_replace("/>",  'title="'.$title111.'"  />',$str2);}
	 else
	 { $str2 =	preg_replace("/title=[\"|\']s*[\"|\']/", 'title="'.$title111.'"',$str2);}


	
    return ( $str2 );
}
/*
部署视频，uedit将编辑器上传的视频，加入控件，使之可以播放
uedit  上传视频 适合 flv 视频，可处理多flv段视频,最多6个
返回 产品字段
*/
function	deployvideo($videostr,$i=1){  //uedit  上传视频 适合 flv 视频
			
				$vstart=stripos($videostr,"<video ");
				if($vstart===false) return $videostr;
				$flvpos=stripos($videostr,'type="video/flv"/>');
				if($i<=6&&$flvpos!==false){$i++;}else return $videostr;  //控制返回
				
				$vend=$flvpos+strlen('type="video/flv"/>');
				$vsubstr=substr($videostr,$vstart,$vend-$vstart);
				$vsubstr1=substr($videostr,0,$vstart);  // 前半部分
				$vsubstr2=substr($videostr,$vend);   // 后半部分
				
				 
				$vfstart=stripos($vsubstr,'<source src="')+strlen('<source src="');
				$vfend=stripos($vsubstr,'.flv') ;
				$vfile=substr($vsubstr,$vfstart,$vfend-$vfstart-1);  //视频文件
				//mecfocus.com/player/flvplayer.swf"
				$vnew='<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> 
     	<li>
			<div id="player_box1"></div></li><script type="text/javascript">
        var s1 = new SWFObject("http://' .$_SERVER['HTTP_HOST']. substr($_SERVER['PHP_SELF'],0,strripos($_SERVER['PHP_SELF'],"/")).'/player/flvplayer.swf","single","450","300","10");
		
        s1.addParam("allowfullscreen","true");
        s1.addParam("wmode","transparent");
        s1.addVariable("file","'.$vfile.'");
        s1.addVariable("image","http://' .$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,strripos($_SERVER['PHP_SELF'],"/")).'/player/cover.jpg");
        s1.addVariable("width","450");
        s1.addVariable("height","300");
        s1.write("player_box1");
    </script>
       </div>
';

	return ($vstart===false?$videostr:deployvideo($vsubstr1.$vnew.$vsubstr2,$i));
}

?>