<?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(($allpages-$i-1)==0)
		{
			$indexp=$moduleFile;
		}
		else
		{
			$indexp=str_replace(".","-".($allpages-$i-1).".",$moduleFile) ;
		}
		$a_p = $allpages-$i;
		if($a_p != $ls_current_page){
			$propage.="<div class=\"propage\"><a data-ajax='false' href=\"".$indexp."\">".($allpages-$i)."</a></div>\r\n";
		}else{
			$propage.="<div class=\"propage\"><div class=\"current_page\">".($allpages-$i)."</div></div>\r\n";
		}
	}
	if($allpages==1)
	{$propage="";}
	else
	{$propage="<div class=\"propageall\">".$propage."</div>\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,$ss_pro_cate,$ss_cate,$ss_pro2_cate,$ss_pro3_cate,$ss_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;
	//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['motifText'] == ""){
			$s_motif_cate.="
			<a href=\"javascript:void(0);\" target=\"_blank\" ><img src=\"../".$MotifFolders."/".$BigFoldersProducts."/".$motif_rows['motifPic']."\" border=\"0\"></a>";
		}else{
			$s_motif_cate.="
			<a href=\"".$motif_rows['motifText']."\" target=\"_blank\" ><img src=\"../".$MotifFolders."/".$BigFoldersProducts."/".$motif_rows['motifPic']."\" border=\"0\"></a>";
		}
		
	}
	$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="<a href=\"../index.html\">Home</a> -> <a href=\"#\">".$myrowsdetail['cateName']."</a>";

		$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;			//左侧产品类别
		$ss_cate=$ss_pro_cate;			//左侧产品类别
		$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 = "<ul class=\"pro_list\">";
		while($midcate_pic_rows=mysql_fetch_assoc($midcate_pic_query)){
			if($midcate_pic_rows['catePic'] != null){
				if(query_subcate($cateid)){
					$mid_pic .= "<li><a href=\"".$midcate_pic_rows['midcateFolders']."/indexdetails.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>";
				}else{
					$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 .= "</ul>";//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="<a href=\"../../index.html\">Home</a> -> <a href=\"../../".$path_pro."\">".$myrowsdetail2['cateName']."</a> -> <a href=\"../../".$myrowsdetail2['cateFolders']."/".$myrowsdetail['midcateFolders']."/".$myrowsdetail['midcateFolders'].".html\">".$myrowsdetail['midcateName']."</a>";
		$prolistfilename = $myrowsdetail['midcateFolders'];
	
		$url="../";
		$leftcate=$pro2_cate;
		$s_cate=$s_pro2_cate;			//左侧产品类别
		$ss_cate=$ss_pro2_cate;			//左侧产品类别
		$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;			//左侧产品类别
		$ss_cate=$ss_pro3_cate;			//左侧产品类别
		
		$site_cate = $s_site4_cate;
		$site_cate_pro = $s_site3_cate;
		$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,$ss_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,$ss_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="<ul class=\"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']."/".$showproductsFolders."/".$pathprofilename."-".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;
					$ss_cate=$ss_pro_cate;
					$s_procate=$s_pro2_cate;	//左侧产品类别
					$ss_procate=$ss_pro2_cate;
					$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']."/".$showproductsFolders."/".$pathprofilename."-".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;	//左侧产品类别
					$ss_cate=$ss_pro2_cate;	//左侧产品类别
					$s_procate=$s_pro3_cate;	//左侧产品类别
					$ss_procate=$ss_pro3_cate;
					$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']."/".$showproductsFolders."/".$pathprofilename."-".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html";
					
					$banner="../../".$search_cate_rows['catePagePic'];
					$lsbrief=$search_subcate_rows['subcateBrief'];
					
					$url="../../";
					$s_cate=$s_pro3_cate;				//左侧产品类别
					$ss_cate=$ss_pro3_cate;				//左侧产品类别
					$s_procate=$s_pro4_cate;				//左侧产品类别
					$ss_procate=$ss_pro4_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;  //产品详细页主题图片
				}
				
				
				//产品
				//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=\"".$showproductsFolders."/".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.="<li><a href=\"".$showproductsFolders."/".$pathprofilename."-".pathProName($products_rows['productName'])."-".$products_rows['ID'].".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' title=\"".$products_rows['productItemNo']."\">".$products_rows['productItemNo']."</a></li>";
					//$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=\"".$showproductsFolders."/".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=\"".$showproductsFolders."/".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=\"".$showproductsFolders."/".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_ss_cate=$ss_procate;				//左侧产品类别
			$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;						//左侧产品类别
			$ls_indicatebar=str_replace("../../","../../../",$indicatebar);
			
			//相关产品 -- 前10产品与后10产品   --有图片
			$related_products = "";
			//前10个产品
			$related_sql="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=$opendb->query($related_sql);
			$related_products.="<ul  class=\"related\">";
			while($related_rows=mysql_fetch_array($related_query)){
				$related_products.="<li><a href=\"../".$showproductsFolders."/".$pathprofilename."-".pathProName($related_rows['productName'])."-".$related_rows['ID'].".html\" target=\"_blank\"><img src=\"../".$SmallFoldersProducts."/".$related_rows['productPic']."\" /></a>".$related_rows['productItemNo']."</li>";
			}
			//后10产品
			$related_sql2="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=$opendb->query($related_sql2);
			while($related_rows2=mysql_fetch_array($related_query2)){
				$related_products.="<li><a href=\"../".$showproductsFolders."/".$pathprofilename."-".pathProName($related_rows2['productName'])."-".$related_rows2['ID'].".html\" target=\"_blank\"><img src=\"../".$SmallFoldersProducts."/".$related_rows2['productPic']."\" /></a>".$related_rows2['productItemNo']."</li>";
			}
			$related_products.="</ul>";
			
			//相关产品 -- 前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=\"../".$showproductsFolders."/".$pathprofilename."-".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=\"../".$showproductsFolders."/".$pathprofilename."-".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'];
			if($ls_morecontent != ""){
				$ls_moreparamstr = "<div class='moreparam'>";							
				$ls_moreparamstr .= "<h4>Quick View</h4>";
				$ls_moreparamstr .= str_replace("\n","<br />",$ls_morecontent); 
				$ls_moreparamstr .= "</div>";
			}else {
				$ls_moreparamstr="";
			}
			/**********************************************************************************/
			//产品属性
			$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 = "<ul class='moreparam'>";
				while($prospec_row=mysql_fetch_assoc($select_query2))  //循环处理变量处理 变量名
				{	
					if(trim($prospec_row['specValue'])!=''){$ls_spec .= "<li><b>".$prospec_row['specName']."</b>: ".$prospec_row['specValue']."</li>\r\n";}	
				}
				$ls_spec .= "</ul><br/>\r\n";
				//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 ."<b>".($productDescriptionTitle==''?'':($productDescriptionTitle."</b>: ")).$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
			
			$tem_sql="select * from ls_config order by ID";	
			$opendb=new mydb();
			$tem_query=$opendb->query($tem_sql);
			$row_code=mysql_fetch_array($tem_query);
			$statistics = $row_code['statistics'];
			$onlines = $row_code['onlines'];
			$maps = $row_code['maps'];
			$share = $row_code['share'];
			$onlinechart = $row_code['onlinechart'];
			$shield = $row_code['shield'];
			
			$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_procate}",$ls_procate,$procontent);
			$procontent  = str_replace("{ls_s_cate}",$ls_s_cate,$procontent);
			$procontent  = str_replace("{ls_ss_cate}",$ls_ss_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("{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_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.="</ul>";
		
		$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,$ss_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){
	$opdb=new mydb();
	//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))?'Previous':'Next')."</a>";
	return str_replace($tag,$targetProductLink,$content);
}

function circleNavigationLink2($productID,$direction,$tag,$content,$pathprofilename){
	$opdb=new mydb();
	//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=$pathprofilename."-".pathProName($targetProduct->productName)."-".$targetProduct->ID.'.html';
	$targetProductLink="<a href=\"{$targetProductFile}\">".(('B'==strtoupper($direction))?'Previous':'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,$ss_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){$ss_cate=str_replace($needleonmouseover,$replaceonmouseover,$ss_cate);}
	//echo $menuListscateid."-pp";
	
	if(!file_exists($index_path)){
		echo "模板文件".$index_path."不存在！请设计好模板后重新生成。</br></br>";
		return;
	}
	
	$tem_sql="select * from ls_config order by ID";	
	$opendb=new mydb();
	$tem_query=$opendb->query($tem_sql);
	$row_code=mysql_fetch_array($tem_query);
	$statistics = $row_code['statistics'];
	$onlines = $row_code['onlines'];
	$maps = $row_code['maps'];
	$share = $row_code['share'];
	$onlinechart = $row_code['onlinechart'];
	$shield = $row_code['shield'];
	$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_ss_cate=$ss_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_ss_cate}",$ls_ss_cate,$content);
	$content = str_replace("{ls_motif}",$ls_motif,$content);
	
	$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_site_cate}",$site_cate_pro,$content);
	$content = str_replace("{weiboshare}",$facebook_twitter_share,$content);
	$content = str_replace("{ls_weibo}",$ls_facebook_twitter,$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_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,$ss_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'];
	$statistics = $row['statistics'];
	$onlines = $row['onlines'];
	$maps = $row['maps'];
	$share = $row['share'];
	$onlinechart = $row['onlinechart'];
	$shield = $row['shield'];
	
	$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 .= "<a href ='".$links_rows['linkURL']."' target='_blank'>".$links_rows['linkTitle']."</a>  |  ";
	}
	$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_ss_cate = $ss_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($subFolder){
		//如果在子目录里面有"../../"则换成"../"
		$content = str_replace("../../","../",$content);}
	else{
		//用来预防根目录下有其他语言版本
		$content = str_replace("../.","../x",$content);
		$content = str_replace("../","",$content);
		$content = str_replace("x./","../",$content);
	}
	
	$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_ss_cate}",$ls_ss_cate,$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);
	
	$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("{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_contact}",$row['contact'],$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);
		
		$news_cate_sql3="select * from `ls_functioncates` where functionName='新闻分类' and enable=1 order by Num desc ";
		$news_cate_query3=$opendb->query($news_cate_sql3);
		$i = 0;
		while($news_cate_rows3=mysql_fetch_assoc($news_cate_query3)){
			$content = str_replace("{ls_news".$news_cate_rows3['suffStr']."}",$ls_news[$i],$content);
			$i++;
		}
		
		$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("</body>",$code,$content);
		break;
		case "aboutus":
		$content = str_replace("{ls_allabout}",$mainpart,$content);
		break;
		case "feedback": 
		$content = str_replace("{ls_feedbackemail}",$ls_feedbackemail,$content);
		$content = str_replace("{ls_feedback}",$mainpart,$content);
		break;
		case "contactus":
		$content = str_replace("{ls_contactus}",$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":
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_newslist}",$mainpart,$content);
		$content = str_replace("{newstag}",$newstag,$content);
		break;
		case "problem":
		$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":
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_classpro}",$ls_classpro,$content);
		break;
		case "download": //生成下载
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_downlist}",$mainpart,$content);
		break;
		case "management": //生成管理团队(Management)
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_list}",$mainpart,$content);
		break;
		case "workshop": //生成车间图片(Workshop)
		$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)
		$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)
		$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)
		$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)
		$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)
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		echo $mainpart;
		$content = str_replace("{ls_list}",$mainpart,$content);
		$content = str_replace("{ls_introduction}",$ls_introduction,$content);
		break;
		case "brand": //生成品牌(Brand)
		$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":
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_hotpro}",$ls_hotpro,$content);
		break;
		case "newpro.html":
		$content = str_replace("{ls_propage}",$ls_propage,$content);
		$content = str_replace("{ls_newpro}",$ls_newpro,$content);
		break;
		case "links.html":
		$linkssql="select * from ls_links where enable=1 order by linkNum asc";
		$linksquery=$opendb->query($linkssql);
		$ls_links="<div class='link'>";
		while($linksitem=mysql_fetch_assoc($linksquery)){			
			$imagepath="uploadfiles/".$linksitem["linkIconPic"];
			if(!file_exists($imagepath) && strlen($linksitem["linkTitle"])!=0){
				$ls_links.="<div class='link_onlytext'>";
				$fontsize=(round(10-strlen($linksitem["linkTitle"])*1.3)>=3)?round(10-strlen($linksitem["linkTitle"])):3;
				$ls_links.="<a href='".$linksitem["linkURL"]."'><font size='".$fontsize."px'>".$linksitem["linkTitle"]."</font></a>";
				$ls_links.="</div>";
				continue;
			}
			$ls_links.="<div class='link_list'>";
			if(file_exists($imagepath)){
				$ls_links.="<a href ='".$links_rows['linkURL']."' target='_blank'>".$links_rows['linkTitle']."</a> |  ";
			}
		
			
			$ls_links.="<br />";
			if(strlen($linksitem["linkTitle"])!=0){
				$ls_links.="<a href='".$linksitem["linkURL"]."'>".$linksitem["linkTitle"]."</a>";
			}
			$ls_links.="</div>";
		}
		$ls_links.="</div>";
		$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){
	
	$opdb=new mydb();
	//Get product information
	$productInfoSql="select * from $db where ID={$ID}";
	$productInfoR=$opdb->query($productInfoSql);
	$productInfo=mysql_fetch_object($productInfoR);
	//Get Max and Min Num value
	$numLimitSql="select min(Num) as minNum, max(Num) as maxNum from $db where cate='$cate' and 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);
			$checkSql="select ID from $db where cate='$cate' and enable ='1' 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 $db where cate='$cate' and enable ='1' and Num={$linkProductNum}";
	$targetProductR=$opdb->query($targetProductSql);
	$targetProduct=mysql_fetch_object($targetProductR);
	$targetProductFile=$fileName.$suffix_str.$targetProduct->ID.".html";
	$targetProductLink="<a href=\"{$targetProductFile}\">".(('B'==strtoupper($direction))?'Previous':'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']."/".$showproductsFolders."/".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']."/".$showproductsFolders."/".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']."/".$showproductsFolders."/".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;
		}
	}
}

//汉字转成拼音字母
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]); 
}

?>