<?
/*
参数：

$products_sql 某类的sql查询串
$PageNum


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

function writeProPageIndex_m($products_sql,$cateid,$midcateid,$subcateid){
	global $PageNum,$s_pro_cate,$s_cate,$s_pro2_cate,$s_pro3_cate,
	$s_pro4_cate,$pro_cate,$cate,$pro2_cate,$pro3_cate,$pro4_cate,$menu,
	$menu_pro,$menu_pro2,$menu_pro3,$menu_pro4,$showproductsFolders,$lsproshowmenu,$foot,
	$SmallFoldersProducts,$BigFoldersProducts,$minCateDetailLength,$detail,$foot,$menuListscateid,$DetailPage,
	$ls_about,$ls_news,$ls_classpro,$ls_hotpro,$ls_designby,$ls_news,$ls_newsdongtai,$ls_newsgonggao,$ls_newstieshi,$ls_procurrentpage,$ls_m_logo,
	$ls_newsall2,$ls_newsdongtai2,$ls_newsgonggao2,$ls_newstieshi2,
	$ls_newsall3,$ls_newsdongtai3,$ls_newsgonggao3,$ls_newstieshi3,
	$ls_newsall4,$ls_newsdongtai4,$ls_newsgonggao4,$ls_newstieshi4,
	$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,
	$productDescriptionTitle,$productshowstyl,$procate_m,$procate_m0,$procate_m1,$procate_m2,$procate_m3,$p_m_cate,$p_m_cate1,$p_m_cate2,$p_m_cate3;
	//echo $menuListscateid."writeProPageIndex";
	//echo $pro_revo."---".$pro2_revo;
	$mynum=0;//总产品数
	$allpages=0;//共有页数
	
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	
	$tem_sql="select * from ls_config order by ID";	
	$tem_query=$opendb->query($tem_sql);
	$row=mysql_fetch_array($tem_query);
	$templates_var = "Templates_m1";
	$mobi_logo = $row['logo'];
	$tel = $row['tel'];
	$ls_m_logo = "<img src='../images/".$mobi_logo."' />";
	$ls_m_logo2 = "<img src='images/".$mobi_logo."' />";
	//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.="
		<ul class=\"slides_container\">";
	
	while($motif_rows=mysql_fetch_assoc($motif_query))
	{
		$s_motif_cate.="
			<li><img src=\"../".$MotifFolders."/".$BigFoldersProducts."/".$motif_rows['motifPic']."\" border=\"0\"></li>";
			
	}
	$s_motif_cate.="
		</ul>\r\n ";*/
	//echo  $s_motif_cate."55555555";exit;
/*	$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  */
	/*$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=$myrowsdetail['cateDetail'];
		}
		$procate=$myrowsdetail['cateName'];
		//$indicatebar="Home-> ".$myrowsdetail['cateName'];
		$indicatebar="<a href=\"../index.html\">Home</a> -> ".$myrowsdetail['cateName'];

		$catetitle=$myrowsdetail['cateTitle'];
		$cateKeywords=$myrowsdetail['cateKeywords'];
		$cateDescription=$myrowsdetail['cateDescription'];
		$banner=$myrowsdetail['catePagePic'];
		
		$pro_file_name = $myrowsdetail['cateFolders'];
		$file=$myrowsdetail['cateFolders']."/".$myrowsdetail['cateFolders'].".html";
		$lsbrief=$myrowsdetail['cateBrief'];
		$echoname="大类".$myrowsdetail['cateName'];
		
		$url="";
		$leftcate=$pro_cate;
		$s_cate=$s_pro_cate;			//左侧产品类别
		$ls_m_cate = $p_m_cate1;
		$ls_m_cate2 = $p_m_cate2;
		$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){
				$sql = "select * from ls_products where ID=".$cateid;
				$cate_pic_row = mysql_fetch_assoc($opendb->query($sql));
					$mid_pic .= "<li><a href=\"".$midcate_pic_rows['midcateFolders']."/indexdetails.html\" onClick=\"document.getElementById('page_products_list').style.display = 'none';\"><div class=\"pic\"><div class=\"col\"><img src='../../".$cate_pic_row['cateFolders']."/".$midcate_pic_rows['midcateFolders']."/".$midcate_pic_rows['catePic']."' width=\"189\" name=\"imgs\"  /></div>
	        </div><div class=\"cont\"><h3>".$midcate_pic_rows['midcateName']."</h3></div></li></a>";

			}
		}
		
		//$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=$myrowsdetail['midcateDetail'];
		}
		$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);
		
		$catetitle=($catetitle=="")?$myrowsdetail2['cateTitle']:$catetitle;
		$cateKeywords=($cateKeywords=="")?$myrowsdetail2['cateKeywords']:$cateKeywords;
		$cateDescription=($cateDescription=="")?$myrowsdetail2['cateDescription']:$cateDescription;
		
		$pro_file_name = $myrowsdetail['midcateFolders'];
		
		$banner="../".$myrowsdetail2['catePagePic'];
		$file=$myrowsdetail2['cateFolders']."/".$myrowsdetail['midcateFolders']."/".$myrowsdetail['midcateFolders'].".html";
		$lsbrief=$myrowsdetail['midcateBrief'];
		$echoname=" 中类".$myrowsdetail['midcateName'];
		$indicatebar="Home-> ".$myrowsdetail2['cateName']." -> ".$myrowsdetail['midcateName'];
		
	
		$url="../";
		$leftcate=$pro2_cate;
		$s_cate=$s_pro2_cate;			//左侧产品类别
		$ls_m_cate = $p_m_cate2;
		$ls_m_cate2 = $p_m_cate3;
		$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){
				$sql = "select * from ls_products where ID=".$midcateid;
				$midcate_pic_row = mysql_fetch_assoc($opendb->query($sql));
				
				$sql = "select * from ls_products where ID=".$midcate_pic_row['midcateID'];
				$cate_pic_row = mysql_fetch_assoc($opendb->query($sql));
				$sub_pic .= "<li><a href=\"".$subcate_pic_rows['subcateFolders']."/index.html\" onClick=\"document.getElementById('page_products_list').style.display = 'none';\"><div class=\"pic\"><div class=\"col\"><img src=\"../../../".$cate_pic_row['cateFolders']."/".$midcate_pic_row['midcateFolders']."/".$subcate_pic_rows['subcateFolders']."/".$subcate_pic_rows['catePic']."\"  name=\"imgs\"  /></div></div><div class=\"cont\"><h3>".$subcate_pic_rows['subcateName']."</h3></div></li></a>";
			}
		}
		
		//$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=$myrowsdetail['subcateDetail'];
		}
		$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";
		
		$pro_file_name = $myrowsdetail['subcateFolders'];
		$lsbrief=$myrowsdetail['subcateBrief'];
		$echoname=" 小类".$myrowsdetail['subcateName'];
		$indicatebar="Home-> ".$myrowsdetail3['cateName']." -> ".$myrowsdetail2['midcateName']." -> ".$myrowsdetail['subcateName'];
		//$indicatebar=$myrowsdetail['subcateName'];


		$url="../../";
		$s_cate=$s_pro3_cate;			//左侧产品类别
		$ls_m_cate = $p_m_cate3;
		$ls_m_cate2 = $p_m_cate4;
		$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="../".$mobi_path.$templates_var."/catedetail.html";	//类详细页面
			$detailsfile=str_replace("index.html","indexdetails.html",$file);
					
			writeIndexPages_m($index_path2,$catetitle,$cateKeywords,$cateDescription,$url,$banner,$leftcate,$lspro_menu,
			$lsbrief,$procate,$procateid,$propage,$pro,$detailsfile,$echoname,$mynum,$allpages,$detail,$s_cate,$ls_m_cate,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf);
			//echo $detail;
			
		}
		if($DetailPage==1)		//0 叶类生成详细说明页面，函数继续执行 1枝类生成详细说明页面，函数返回
		{
			$DetailPage=0; //reset flag
			return;
		}		
		$products_sql.=" order by Num asc ";
		$result=$opendb->query($products_sql);
		$result2=$opendb->query($products_sql);		//for the browseNo
		$mynum = mysql_num_rows($result);//总产品数
		// 每页数量
		$onepage = $PageNum_pro_m; 
		//共有页数
		$allpages = ceil($mynum/$onepage);
		if($mynum==0)  // 没有产品
		{
			$echoname="无产品: ".$echoname;
			$mynum=0;
			$allpages=1;
			
			
			$index_path="../".$mobi_path.$templates_var."/catedetail.html";	//没产品，输出 详细页或者 产品页没内容

			if(is_file($index_path)){}
			else
			{$index_path="../".$mobi_path.$templates_var."/products.html";}
			
			writeIndexPages_m($index_path,$catetitle,$cateKeywords,$cateDescription,$url,$banner,$leftcate,$lspro_menu,
			$lsbrief,$procate,$procateid,$propage,$pro,$file,$echoname,$mynum,$allpages,$detail,$s_cate,$ls_m_cate,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf);
			return;
		}
		
			//end  没有产品或者类别详细页面有内容只生成 类别单页
			
			//echo $products_sql."共有".$mynum."个产品。可以生成".$allpages."页.每页".$onepage."个<br>";
			
			//页码计算
			//$propage=getpages("index.html",$allpages);
			//页码计算
			
			$j=1;
			
			for ($i=0; $i<$allpages; $i++)
			{ 
				$ls_procurrentpage="";
				if ($i == 0)
				{ 
				$indexpath = $pro_file_name.".html";
				} 
				else 
				{ 
				  $indexpath = $pro_file_name."-".$i.".html";
				}
				$start = $i * $onepage;
				if($allpages!=1){
					$ls_procurrentpage="[".($i+1)."]";		//当前页码
					$ls_current_page=$i+1;
				}
				//$pro="<ul class=\"pro_list\">";
		 //查询产品
		 
			 $products_sql2=$products_sql." limit ".$start.",".$onepage." ";
			 //echo $products_sql2."<br>";
			 $products_query=$opendb->query($products_sql2);
			 $pro = "";
			 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;
					$pathprofilename = $search_subcate_rows['cateFolders'];
					//$pathprofilename = $search_subcate_rows['cateFolders'];
					//生成大图地址
					$profile=$search_subcate_rows['cateFolders']."/".$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;
					$s_procate=$s_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'];
					
					$pathprofilename = $search_subcate_rows['midcateFolders'];
					//生成文件地址
					$file=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders']."/".$indexpath;
					//生成大图文件地址
					$profile=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders']."/".$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;	//左侧产品类别
					$s_procate=$s_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;
					$pathprofilename = $search_subcate_rows['subcateFolders'];
					//生成大图地址
					$profile=$search_cate_rows['cateFolders']."/".$search_midcate_rows['midcateFolders']."/".$search_subcate_rows['subcateFolders']."/".$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;				//左侧产品类别
					$s_procate=$s_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;  //产品详细页主题图片
				}
				
				
				//查询图片的路径
			$pro_m_str='';
			$sql = "select * from ls_products where ID=".$products_rows['productID'];
			$cate_m = mysql_fetch_assoc($opendb->query($sql));
			if($cate_m['cateName']!='' ){
					$pro_m_str .= $cate_m['cateFolders'];
				}
			if($cate_m['midcateName']!='') {
					$sql = "select * from ls_products where ID=".$cate_m['midcateID'];
					$cate_m2 = mysql_fetch_assoc($opendb->query($sql));
					$pro_m_str .= "../".$cate_m2['cateFolders']."/".$cate_m['midcateFolders'];
					
				}
				
			if($cate_m['subcateName']!='') {
					$sql= "select * from ls_products where ID =".$cate_m['subcateID'];
					$cate_m3 = mysql_fetch_assoc($opendb->query($sql));
					
					$sql = "select * from ls_products where ID=".$cate_m3['midcateID'];
					$cate_m4 = mysql_fetch_assoc($opendb->query($sql));
					$pro_m_str .= "../../".$cate_m4['cateFolders']."/".$cate_m3['midcateFolders']."/".$cate_m['subcateFolders'];
				}
			//echo "<h1 style='color:red;'>".$pro_m_str."</h1>";
			$ls_proshow="../../../".$pro_m_str."/".$BigFoldersProducts."/".$products_rows['productPic']."\" ";//大图
				
			$ls_proshowlist="../../".$pro_m_str."/".$BigFoldersProducts."/".$products_rows['productPic'];
			
			$imgpic = "../../".$pro_m_str.'/'.$imgpic;
				//产品
				//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>		<a href=\"".trim(str_replace(substr($products_rows['productPic'],-4),'',$products_rows['productPic'])).".html\">
	        <div class=\"cont\">
				<h3>".$products_rows['productName']."
				</h3>
				<p class=\"detail\">".$products_rows['productItemNo']."
				</p>      
	        </div>
			</a></li>";
		
					break;
			
					case "list":
					$pro.="<li ><a href=\"".$pathprofilename."-".pathProName($products_rows['productName'])."-".$products_rows['ID'].".html\" alt=\"".$products_rows['productItemNo']."\" ><img src=\"".$imgpic."\"  alt=\"".$products_rows['productItemNo']."\"/></a><span class=\"p_title\">".$products_rows['productName']." </span></li>";
					break;
					
					case "style4":
					$pro.="<li id='pro_list_li_style4' ><a id='pro_list_li_a_name' href=\"".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\">".$products_rows['productItemNo']."</a></li>\r\n";
					break;
					
					case "style5":
					$pro.="<li id='pro_list_li_style4' ><a id='pro_list_li_a_name' href=\"".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\">".$products_rows['productItemNo']."</a></li>\r\n";
					break;
					
					
					case "":
					case "gallary":
					default:
					$pro.="<li><a href=\"".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\"><img width=\"".($showSmallPicW!=""?$showSmallPicW:'188')."\" src=\"".$imgpic."\" alt=\"".$products_rows['productItemNo']."\" /></a>".$products_rows['productItemNo']."</li>\r\n";
					
				}
				//}else{
					//$pro.="<li><a href=\"".$showproductsFolders."/".trim(str_replace(substr($products_rows['productPic'],-4),"",$products_rows['productPic'])).".html\" alt=\"".$products_rows['productItemNo']."\" target=\"_blank\"><img src=\"".$imgpic."\" alt=\"".$products_rows['productItemNo']."\" /></a>".$products_rows['productItemNo']."</li>";
				//}				   
			
		//页码计算
		$propage=getPagess($pathprofilename.".html",$allpages,$ls_current_page);


		$proshow_path="../".$mobi_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']==''?"":$products_rows['productDescription'];		//产品Description
			$ls_prourl=$url;
			$ls_s_cate=$s_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(" ", "&nbsp;", $indicatebar);

			$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 != ""){
				$morearray = explode('
', $ls_morecontent);
				$newarray = array();
				foreach($morearray as $moreval){
					$morearray2 = explode(':', $moreval);
					$newarray[] = $morearray2;
				}
				$ls_moreparamstr = "<table width=\"100%\" border=\"0\" style=\"line-height:20px;\">";
				$num_i = 0;
				foreach($newarray as $newval){
					if(($num_i%2)==0){
						$ls_moreparamstr .= "<tr><td><span>".$newval[0]."</span>: ".$newval[1]."</td>";
					}else{
						$ls_moreparamstr .= "<td><span>".$newval[0]."</span>: ".$newval[1]."</td></tr>";
					}
					$num_i++;
				}
				$ls_moreparamstr .= "</table>"; 
			}else {
				$ls_moreparamstr="";
			}
			$ls_moreparamstr2 = str_replace("\n","<br />",$products_rows['canshu2']);
			/**********************************************************************************/
			//产品属性
			$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="".$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);			//删除两端的空白字符
			
			$ls_prodescription=$ls_spec ."<b>".($productDescriptionTitle==''?'':($productDescriptionTitle."</b>: ")).$ls_prodescription;
				if(strlen($ls_prodescription_test)!=0){
				$ls_prodescription=$ls_spec .$ls_prodescription;
			} else {
				$ls_prodescription=null;
			}
			
			
			$ls_foot=$foot;	
			

// 深入一级目录，适应 productshow
			$ls_pronewsdongtai=str_replace('="../','="../../',$ls_newsdongtai);		
			$ls_pronewsgonggao=str_replace('="../','="../../',$ls_newsgonggao);
			$ls_pronewstieshi=str_replace('="../','="../../',$ls_newstieshi);
												//底部信息
												

//组合数字导航
			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;
			$ls_m_procate = $procate_m1;
			
//组合数字导航 end
			$j++;
			$fp = fopen($proshow_path,"r");
			
			$procontent  = fread($fp,filesize ($proshow_path));
			$procontent  = str_replace("{ls_m_logo}",$ls_m_logo,$procontent);
			$procontent  = str_replace("../","{ls_url}../../",$procontent);
			$procontent	= str_replace("{ls_m_procate}",$ls_m_procate,$procontent);
			$procontent  = str_replace("{ls_title}",$ls_protitle."-".$row['companyName'],$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_procate}",$ls_procate,$procontent);
			$procontent  = str_replace("{ls_m_tel}",$tel,$procontent);
			$procontent  = str_replace("{ls_s_cate}",$ls_s_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_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}",$lspro_motif,$procontent);
			
			$procontent = str_replace("{ls_m_cate}",$ls_m_cate2,$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_classpro}",$ls_classpro,$procontent);
			$procontent	= str_replace("{ls_hotpro}",$ls_hotpro,$procontent);
			$procontent	= str_replace("{ls_designby}",$ls_designby,$procontent);
			$procontent	= str_replace("{ls_link}",$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_moreparam2}",$ls_moreparamstr2,$procontent);//产品详细页中，除了产品名称、编号外的更多信息。
			$procontent = str_replace("{ls_revo}",$ls_revo,$procontent);//滚动图片。

			$procontent = circleNavigationLink2($products_rows['ID'],'F','{ls_nextlink}',$procontent,$pathprofilename);
			$procontent = circleNavigationLink2($products_rows['ID'],'B','{ls_previouslink}',$procontent,$pathprofilename);
			$procontent = str_replace("{ls_search}",ls_search("../../".$ls_prourl),$procontent); //搜索框

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

			$profilename="../m/".$profile;
			$arr = explode("/",$profilename);
			array_pop($arr);
			$profilename1=implode("/",$arr);
			
			if(!is_dir($profilename1)) {
					mkdir($profilename1,0775,true);
				}
			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="../".$mobi_path.$templates_var."/products.html";	
		writeIndexPages_m($index_path,$catetitle,$cateKeywords,$cateDescription,$url,$banner,$leftcate,$lspro_menu,
			$lsbrief,$procate,$procateid,$propage,$pro,$file,$echoname,$mynum,$allpages,$detail,$s_cate,$ls_m_cate,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf);
//echo $pro;

		}	// end of for, all pages


		$opendb->close();
}

/*
------------------------------------------------------
参数：
$leftcate
$leftcate
$pro
$file
$echoname

$indicatebar
程序功能：写入类下产品列表页index文件
------------------------------------------------------
*/
function writeIndexPages_m($index_path,$catetitle,$cateKeywords,$cateDescription,$url,$banner,$leftcate,$lspro_menu,$lsbrief,$procate,$procateid,$propage,$pro,$file,$echoname,$mynum,$allpages,&$detail,$s_cate,$ls_m_cate,$ls_motif,$ls_revo,$foot,$indicatebar,$behalf){
	global $ls_procurrentpage,$menuListscateid,$ls_about,$ls_news,$ls_classpro,$ls_hotpro,$ls_link,$ls_designby,$ls_news,$ls_newsdongtai,$ls_newsgonggao,$ls_newstieshi,$ls_addprolink,$ls_addnewprolink,$ls_moreparam,$procate_m,$ls_m_logo,$p_m_cate,$p_m_cate1,$p_m_cate2,$p_m_cate3;
	
	$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);}
	
	//echo $menuListscateid."-pp";
			
	if(!file_exists($index_path)){
		echo "模板文件".$index_path."不存在！请设计好模板后重新生成。</br></br>";
		return;
	}

	$ls_m_procate = $procate_m;
	
	//产品模板地址
	$ls_title=$catetitle;//===================================网站标题
	$ls_keywords=$cateKeywords;	//============================网站关键字
	$ls_description=$cateDescription;//=======================网站描述
	$ls_url=$url;
	$ls_banner=$banner;//=====================================大类主体图
	$ls_cate=$leftcate;	
	$ls_s_cate=$s_cate;//=====================================左侧产品类别
	$ls_menu=$lspro_menu;//主菜单
	$ls_indicatebar=str_replace(" ", "&nbsp;", $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_m_procate = str_replace("{ls_url}",$ls_url,$ls_m_procate);
	$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_m_logo}",$ls_m_logo,$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_motif}",$ls_motif,$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_m_cate}",$ls_m_cate,$content);  //手机产品分类
	
	$content = str_replace("{ls_m_procate}",$ls_m_procate,$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_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_link}",$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="../m/".$file;
	
	$arr = explode("/",$filename);
	array_pop($arr);
	$filename1=implode("/",$arr);
			
	if(!is_dir($filename1)) {
		mkdir($filename1,0775,true);
	}
	
	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=="../".$mobi_path.$templates_var."/catedetail.html"){
		echo $echoname." 详细页面成功。<br><br>";
	}else{
		echo $echoname."共有".$mynum."个产品。总共生成".$allpages."类别页。<br><br>";
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
</body>
</html>
