<?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,$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");
		}
	} else {  //文字水印
		$temp = imagettfbbox(ceil($wtFont*2.5),0,"./cour.ttf",$wtString);//取得使用 TrueType 字体的文本的范围
		$wtmwidth = $temp[2] - $temp[6];
		$wtmheight = $temp[3] - $temp[7];
		unset($temp);
	}
		//copy($picFile,$wtmfile);
		$GLOBALS['wPic']=$wtmfile;

		switch($wtPosition) {
 
		case 3://1为顶端居中
			$posX = ($srcwidth - $wtmwidth) / 2;
			$posY = ($srcheight - $wtmheight) / 4;
			break;
		
		case 2://2为中部居中
			$posX = ($srcwidth - $wtmwidth) / 2;
			$posY = ($srcheight - $wtmheight) / 2;
			break;
	   
		case 1://8为底端居中
			$posX = ($srcwidth - $wtmwidth) / 2;
			$posY =($srcheight - $wtmheight) / 4 *3;
			break;
		  
	}
	imagesavealpha($im2,true);  //透明处理
	imagesavealpha($im,true);

	//读取水印文件
	if($wtType=="pic")//水印图片
	{
		//拷贝水印到目标文件
		imagecopy($im, $im2,$posX,$posY, 0, 0, $wtmwidth,$wtmheight);
	}
	else// string
	{
		$R = hexdec(substr($wtColor,1,2));
		$G = hexdec(substr($wtColor,3,4));
		$B = hexdec(substr($wtColor,5));
		imagestring ($im, $wtFont, $posX, $posY, $wtString, imagecolorallocate($im, $R, $G, $B));	   
	}
	
	
	//输出图片
	$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){
	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_problem,$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;
	//echo $menuListscateid."writeProPageIndex";
	//echo $pro_revo."---".$pro2_revo;
	$mynum=0;//总产品数
	$allpages=0;//共有页数
	$pathprofilename = ""; //新型产品详细页文件名
	
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	
	//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\">Главная</a></li> <li><a href=\"../".$myrowsdetail['cateFolders']."/".$myrowsdetail['cateFolders'].".html\">".$myrowsdetail['cateName']."</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;			//左侧产品类别
		$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);
		
		$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."";
		$midcate_pic_query=$opendb->query($midcate_pic_sql);
		
		$mid_pic = "<div class=\"row pro_list\">";
		while($midcate_pic_rows=mysql_fetch_assoc($midcate_pic_query)){
			if($midcate_pic_rows['catePic'] != null){
				if(query_subcate($cateid)){
					$mid_pic .= "<div class=\"col-lg-4 col-md-4 col-sm-6 col-xs-12\"><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']."\" width=\"189\" name=\"imgs\" alt=\"".$midcate_pic_rows['midcateName']."\" /></a></div><div class=\"caption pro-name\"><h5><a href=\"".$midcate_pic_rows['midcateFolders']."/".$midcate_pic_rows['midcateFolders'].".html\">".$midcate_pic_rows['midcateName']."</a></h5></div></div></div>";
				}else{
					$mid_pic .= "<div class=\"col-lg-4 col-md-4 col-sm-6 col-xs-12\"><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']."\" width=\"189\" name=\"imgs\" alt=\"".$midcate_pic_rows['midcateName']."\" /></a></div><div class=\"caption pro-name\"><h5><a href=\"".$midcate_pic_rows['midcateFolders']."/".$midcate_pic_rows['midcateFolders'].".html\">".$midcate_pic_rows['midcateName']."</a></h5></div></div></div>";
					//$mid_pic .= "<li><a href=\"".$midcate_pic_rows['midcateFolders']."/index.html\"><img src=\"".$midcate_pic_rows['midcateFolders']."/".$midcate_pic_rows['catePic']."\" width=\"189\" name=\"imgs\" alt=\"".$midcate_pic_rows['midcateName']."\" /></a>".$midcate_pic_rows['midcateName']."</li>";
				}
			}
		}
		
		$mid_pic .= "</div>";//echo $mid_pic;
		$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";
		$path_pro=$myrowsdetail2['cateFolders']."/".$rows_path['midcateFolders']."/".$rows_path['midcateFolders'].".html";
		$lsbrief=$myrowsdetail['midcateBrief'];
		$echoname=" 中类".$myrowsdetail['midcateName'];
		$indicatebar="<li><a href=\"../../index.html\">Главная</a></li> <li><a href=\"../../".$path_pro."\">".$myrowsdetail2['cateName']."</a></li> <li><a href=\"../../".$myrowsdetail2['cateFolders']."/".$myrowsdetail['midcateFolders']."/".$myrowsdetail['midcateFolders'].".html\">".$myrowsdetail['midcateName']."</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;			//左侧产品类别
		$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);
		
		$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']."\" width=\"189\" 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="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;			//左侧产品类别
		$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);
		
		$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,$s_f_cate,$site_cate_pro,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf,$ls_facebook_twitter2);
			//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,$s_f_cate,$site_cate_pro,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf,$ls_facebook_twitter2);
			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'];
					$profile=$search_subcate_rows['cateFolders']."/".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html";
						
					$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;
					$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'];
					$profile=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders']."/".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html";

					$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;
					$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'];
					$profile=$search_cate_rows['cateFolders']."/".$search_midcate_rows['midcateFolders']."/".$search_subcate_rows['subcateFolders']."/".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html";
					
					$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;
					$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 col-md-4 col-sm-6 col-xs-12\"><div class=\"thumbnail\"><div class=\"img-pic\"><a href=\"".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html\" alt=\"".$products_rows['productItemNo']."\" class=\"c-img-height\" ><img src=\"".$imgpic."\" alt=\"".$products_rows['productItemNo']."\" alt=\"".$products_rows['productItemNo']."\" /></a></div><div class=\"caption pro-name\"><h5><a href=\"".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html\" alt=\"".$products_rows['productItemNo']."\" title='".$products_rows['productItemNo']."' >".$products_rows['productItemNo']."</a></h5></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;
			$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 src=\"".$SmallFoldersProducts."/".$related_rows['productPic']."\" alt='".$related_rows['productItemNo']."' class=\"img-responsive\" /></a></div><div class=\"caption pro-name\"><h5><a href=\"../".$showproductsFolders."/".$pathprofilename."-".pathProName($related_rows['productName'])."-".$related_rows['ID'].".html\" title='".$related_rows['productItemNo']."' >".$related_rows['productItemNo']."</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 src=\"".$SmallFoldersProducts."/".$related_rows2['productPic']."\" alt='".$related_rows['productItemNo']."' class=\"img-responsive\"  /></a></div><div class=\"caption pro-name\"><h5><a href=\"../".$showproductsFolders."/".$pathprofilename."-".pathProName($related_rows2['productName'])."-".$related_rows2['ID'].".html\" title='".$related_rows2['productItemNo']."' >".$related_rows2['productItemNo']."</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_morecontent = $products_rows['canshu'];
			
			$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":
						$statistics = $code_row['code'];
					break;
					case "onlines":
						$onlines = $code_row['code'];
					break;
					case "maps":
						$maps = $code_row['code'];
					break;
					case "share":
						$share = $code_row['code'];
					break;
					case "productsKeywords":
						$productsKeywords = $code_row['code'];
					break;
					case "onlinechart":
						$onlinechart = $code_row['code'];
					break;
					case "shield":
						$shield = $code_row['code'];
					break;
				}
			}
			
			$j++;
		
			$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_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_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("{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_problem}",$ls_problem,$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_moreparam}",$ls_moreparamstr,$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); //搜索框

			//echo $procontent;
			//echo $content;

			$profilename="../".$profile;
			if (is_file ($profilename))
			{ 
				@unlink ($profilename); //若文件已存在，则删除
			  }

	  $handle   = fopen($profilename,"w"); //打开文件指针，
		  /*
		　检查文件是否被创建且可写
		  */
		  if (!is_writable ($profilename))
			{ 
					 echo "文件：".$profilename."不可写，请检查其属性后重试！";
			  }
		  if (!fwrite ($handle,$procontent))
		  {  //将信息写入文件
				echo "".$profilename."失败！";
		  } 
		  else
		  {
				echo "生成 <a href='".$profilename."'>".$profilename."</a><br>";
		  }
		  fclose ($handle); //关闭指针
					  //die ("创建<a href='".$filename."'>".$filename."</a>成功！<a href=\"temp.php?ls=normal\"><u>返回</u></a>");

		fclose ($fp);

	 } //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,$s_f_cate,$site_cate_pro,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf,$ls_facebook_twitter2);
//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);
}
/*
------------------------------------------------------
参数：
$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,$s_f_cate,$site_cate_pro,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf,$ls_facebook_twitter2){
	global $ls_procurrentpage,$menuListscateid,$ls_about,$ls_news,$ls_classpro,$ls_hotpro,$ls_link,$ls_designby,$ls_news,$ls_problem,$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)){
		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":
				$statistics = $code_row['code'];
			break;
			case "onlines":
				$onlines = $code_row['code'];
			break;
			case "maps":
				$maps = $code_row['code'];
			break;
			case "share":
				$share = $code_row['code'];
			break;
			case "productsKeywords":
				$productsKeywords = $code_row['code'];
			break;
			case "onlinechart":
				$onlinechart = $code_row['code'];
			break;
			case "shield":
				$shield = $code_row['code'];
			break;
		}
	}
	
	$ls_facebook_twitter = $ls_facebook_twitter2;

	//产品模板地址
	$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_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_problem}",$ls_problem,$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); //搜索框

	$filename="../".$file;
	if (is_file($filename)){
		//若文件已存在，则删除
		@unlink($filename); 
	}

	$handle = fopen($filename,"w"); //打开文件指针，
	/*
	　检查文件是否被创建且可写
	*/
	if(!is_writable($filename)){ 
		echo "文件：".$filename."不可写，请检查其属性后重试！";
	}
	if(!fwrite($handle,$content)){
		//将信息写入文件
		echo "生成文件".$filename."失败！";
	}else{
		echo "生成 <a href='".$filename."'>".$filename."</a><br>";
	}
	
	fclose($handle);//关闭文件指针
	fclose($fp);	//关闭文件指针
	
	if($index_path=="../".$templates_var."/catedetail.html"){
		echo $echoname." 详细页面成功。<br><br>";
	}else{
		echo $echoname."共有".$mynum."个产品。总共生成".$allpages."类别页。<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_addprolink,$ls_addnewprolink,$newstag,$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_problem,$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;	//首页About us, 首页News, 首页 Hot products

	$opendb=new mydb();
	require('char_set.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'];
	
	$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":
				$statistics = $code_row['code'];
			break;
			case "onlines":
				$onlines = $code_row['code'];
			break;
			case "maps":
				$maps = $code_row['code'];
			break;
			case "share":
				$share = $code_row['code'];
			break;
			case "indexKeywords":
				$indexKeywords = $code_row['code'];
			break;
			case "onlinechart":
				$onlinechart = $code_row['code'];
			break;
			case "shield":
				$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);
	
	$ls_facebook_twitter = str_replace("../","",$facebook_twitter);//cate
	
	$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;
	}
	
	//首页友情链接
	$links_sql = "select * from ls_links where enable = 1";
	$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;
	
	//首页视频
	$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;
	
	$fp = fopen($index_path,"r");
	$ls_s_cate = $s_cate;				//左侧产品类别
	$ls_p_cate = $s_p_cate;				//左侧产品类别
	$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{
		$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_links}",$ls_links,$content);
	$content = str_replace("{ls_about}",$ls_about,$content);
	
	require('constant.php');
		
	//首页新闻列表 Start
		$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;
			if($news_cate_rows3['suffStr'] != "faq"){
				$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);
				while($news_rows=mysql_fetch_assoc($news_query)){
					$nui ++;
					$suffix_str2 = $news_cate_rows3['suffStr'];
					
					$news.="<li>
						<h4><a href=\"".$newsshowFolders."/news".$suffix_str2.$news_rows['ID'].".html\">".$news_rows['newsTitle']."</a></h4>
				 	 <p>".mb_substr(strip_tags($news_rows['newsText']),0,80,'utf-8')."...</p>
					</li>";
				}
				$news.="";
			}else{
				$news_sql="select * from ls_news where cate = '".$news_cate_rows3['cateName']."' and enable=1 order by $sort desc limit 0, 2";
				$news_query=$opendb->query($news_sql);
				$news = "";
				while($news_rows=mysql_fetch_assoc($news_query)){
					$suffix_str2 = $news_cate_rows3['suffStr'];
					
					$news.="<dl class=\"dl-horizontal faqs\">
							  <dt><img src=\"images/question_ico.png\" /></dt>
							  <dd><a href=\"".$newsshowFolders."/news".$suffix_str2.$news_rows['ID'].".html\"><div class=\"faq-T\">".$news_rows['newsTitle']."</div></a></dd>
							  <dt><img src=\"images/reply_ico.png\" /></dt>
							  <dd>".$news_rows['newsText']."</dd>
							 </dl>";
				}
			}
			$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_weibo}",$ls_facebook_twitter,$content);
	$content = str_replace("{ls_weiboshare}",$facebook_twitter_share,$content);
	$content = str_replace("{ls_problem}",$ls_problem,$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_designby}",$ls_designby,$content);
	$content = str_replace("{ls_cate}",$ls_cate,$content);
	$content = str_replace("{ls_foot}",$ls_foot,$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":
		$content = str_replace("{ls_allabout}",$mainpart,$content);
		$content = str_replace("{ls_notice}",$row['notice'],$content);
		$content = str_replace("{ls_video}",$ls_video,$content);
		$content = str_replace("{ls_indexKeywords}",$indexKeywords,$content);

		//首页证书展示 Start
		$products_sql="select * from ls_certificate where enable=1 ";
		$products_sql.=" order by Num asc ";
		$products_query=$opendb->query($products_sql);
		$homecer="";
		$animation = array("bounceInLeft", "bounceInUp", "bounceInUp", "bounceInRight");
		$count=0.4;
		$i = 0;
		while($news_rows=mysql_fetch_assoc($products_query)){
			$count = $count + 0.2;
			$homecer.="<div class=\"col-lg-3 col-md-3 col-sm-6 col-xs-12\">
				<div data-wow-delay=\"".$count."s\" class=\"span3 wow ".$animation[$i]." center\"><img src=\"certificate/images/".$news_rows['Pic']."\" class=\"img-thumbnail img-responsive\"/></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=\"fair/fair-page".$news_rows['ID'].".html\"><img src=\"fair/images/".$news_rows['Pic']."\" class=\"img-thumbnail img-responsive\"/></a></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_certificate}",$homecer,$content);
		$content = str_replace("{ls_packing}",$homepack,$content);
		
		$content = str_replace("</body>",$code,$content);
		break;
		case "aboutus":
		$ls_indicatebar = "<li><a href=\"../ru/index.html\">Главная</a></li>
                           <li class=\"active\">о нас</li>";
		$content = str_replace("{ls_indicatebar}",$ls_indicatebar,$content);
		
		$content = str_replace("{ls_allabout}",$mainpart,$content);
		break;
		case "feedback": 
		$ls_indicatebar = "<li><a href=\"../ru/index.html\">Главная</a></li>
                           <li class=\"active\">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=\"../ru/index.html\">Главная</a></li>
                           <li class=\"active\">свяжитесь с нами</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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\" style='text-transform : capitalize;'>".$suffix_str2."</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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\" style='text-transform : capitalize;'>".$suffix_str2."</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 = 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 "problem":
		$ls_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">FAQs</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\">Главная</a></li>
                           <li class=\"active\">Продукты</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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">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);
		break;
		case "workshop": //生成车间图片(Workshop)
		$ls_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">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": //生成车间图片(Workshop)
		$ls_indicatebar = "<li><a href=\"../ru/index.html\">Главная</a></li>
                           <li class=\"active\">Сертификат качества</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_indicatebar = "<li><a href=\"../index.html\">Home</a></li>
                           <li class=\"active\">R&D</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_indicatebar = "<li><a href=\"../index.html\">Home</a></li>
                           <li class=\"active\">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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">Fair</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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">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 "hotpro.html":
		$ls_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">Hot Products</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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">New Products</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_indicatebar = "<li><a href=\"../index.html\">Главная</a></li>
                           <li class=\"active\">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;

	}
		  
	$handle = fopen($filename,"w"); //打开文件指针，
	//var_dump($filename);exit;
		  /*
		　检查文件是否被创建且可写
		  */
		
	if (!is_writable ($filename))
	{ 
		echo "<script>alert('文件：".$filename."不可写，请检查其属性后重试！');history.go(-1);</script>";
	}
	if (!fwrite ($handle,$content))
	{  //将信息写入文件
		echo "<script>alert('生成文件".$filename."失败！');history.go(-1);</script>";
	} 
	fclose ($handle); //关闭指针
	echo "创建 <a href='".$filename."'>".$filename."</a>成功！<a href=\"temp.php?ls=normal\"><u>返回</u></a><br/><br/>";
}
/*
------------------------------------------------------
参数：
$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);
}

/*------------------------------------------------------
//  递归建立文件夹及子文件夹
//　使用方法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;
	
	
}

/*
------------------------------------------------------
参数：
$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);
					
					//获取图片宽与高
					if(strpos($imgurl,'http') !== false){
						$imgurl2 = $imgurl;
					}else{
						$imgurl2 = "http://".$_SERVER['SERVER_NAME'].$imgurl;
					}
					$image_content = file_get_contents($imgurl2); 
					$image = imagecreatefromstring($image_content); 
					$width = imagesx($image);
					$height = imagesy($image);
					
					$imgWidth = $width;
					$imgHeight = $height;
					
					$proportion = $imgWidth/$imgHeight;
					if($proportion > (600/370)){
						$proportion = "width='".($proportion*370)."' height='370' ";
					}else{
						$proportion = " width='600' height='".(600/$proportion)."' ";
					}
					
					$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;
	}

}

?>