Current Path : /www/users/H10079900/inc/
Url:
Current File : /www/users/H10079900/inc/LQ_templatesFun.php

<?php
//分页函数
function LQgenpage($sql,$page_size)
{
      global $prepage,$nextpage,$pages,$sums;
      $page = $_GET["page"]>=1?$_GET["page"]:0;
      $eachpage = $page_size;
      $pagesql = strstr($sql," from ");
      $pagesql = "select count(*) as ids ".$pagesql;
      $result = mysql_query($pagesql);
      if($rs = mysql_fetch_array($result)) $sums = $rs[0];
      $pages = ceil(($sums-0.5)/$eachpage)-1;
      $pages = $pages>=0?$pages:0;
      $prepage = ($page>0)?$page-1:0;
      $nextpage = ($page<$pages)?$page+1:$pages;  
      $startpos = $page*$eachpage;
    $sql .=" limit $startpos,$eachpage ";
	$s[0]=$sql;
	$s[1]=$sums;
	return $s;
}

//显示分页(中)
function LQshowpage_cn($url)
{
    global $page,$pages,$prepage,$nextpage,$queryString;
    $shownum =10/2;
    $startpage = ($page>=$shownum)?$page-$shownum:0;
    $endpage = ($page+$shownum<=$pages)?$page+$shownum:$pages;
    echo "共&nbsp;<span class='C_redFont'>".($pages+1)."</span>&nbsp;页:&nbsp;"; 
    if($page>0)echo "<a href=".$url."page=0&$queryString>第一页</a>";
    if($startpage>0)
        echo " ... <b><a href=".$url."page=".($page-$shownum*2)."&$queryString>&laquo;</a></b>";
    for($i=$startpage;$i<=$endpage;$i++)
    {
        if($i==$page)echo "&nbsp;<b class='C_redFont_fousc'>[".($i+1)."]</b>&nbsp;";
        else         echo "&nbsp;<a href=".$url."page=$i&$queryString>".($i+1)."</a>&nbsp;";
    }
    if($endpage<$pages)
        echo "<b><a href=".$url."page=".($page+$shownum*2)."&$queryString>&raquo;</a></b> ... ";
    if($page<$pages)
        echo "<a href=".$url."page=$pages&$queryString>最后页</a>";
	echo "&nbsp;&nbsp;<input name='manpage' type='text' id='manpage' size='2' onBlur='chkIntC(this)'  style='text-align:center;width:30px;height:12px;'/>  <a class='goPage' href='#' onClick='location.href=\"".$url."page=\"+(manpage.value-1)+\"\"';'>跳转</a>&nbsp;";
}

//显示分页(英)
function LQshowpage_en($url)
{
    global $page,$pages,$prepage,$nextpage,$queryString;
    $shownum =10/2;
    $startpage = ($page>=$shownum)?$page-$shownum:0;
    $endpage = ($page+$shownum<=$pages)?$page+$shownum:$pages;
    
    if($page>0){echo "<a href=".$url."page=".($page-1)."&$queryString>&nbsp;&lt;&nbsp;</a>&nbsp;";}else{ echo"&nbsp;&lt;&nbsp;";}
    if($startpage>0)
        echo " ... <b><a href=".$url."page=".($page-$shownum*2)."&$queryString>&laquo;</a></b>";
    for($i=$startpage;$i<=$endpage;$i++)
    {
        if($i==$page)echo "&nbsp;<b>".($i+1)."</b>&nbsp;";
        else         echo "&nbsp;<a href=".$url."page=$i&$queryString>".($i+1)."</a>&nbsp;";
    }
    if($endpage<$pages)
        echo "<b><a href=".$url."page=".($page+$shownum*2)."&$queryString>&raquo;</a></b> ... ";
    if($page<$pages){
        echo "&nbsp;<a href=".$url."page=".($page+1)."&$queryString>&nbsp;&gt;&nbsp;</a>";
	}else{
		echo "&nbsp;&gt;&nbsp;";	
	}
}


//反替换特殊字符
function LQfth($thstring,$flg="")
{          
   $thstring=ereg_replace("&amp;","&",$thstring);
   $thstring=ereg_replace("&lt;","<",$thstring);
   $thstring=ereg_replace("&gt;",">",$thstring);
   if(!$flg)
   {
	   $thstring=ereg_replace("<br>",chr(13),$thstring);
	   $thstring=ereg_replace("&nbsp;",chr(32),$thstring);
	   $thstring=ereg_replace("&nbsp;&nbsp;&nbsp;&nbsp;",chr(9),$thstring);
	   $thstring=ereg_replace("&acute;",chr(39),$thstring);
	   $thstring=ereg_replace("&quot;",chr(34),$thstring);
	}
return $thstring;
}



//替换用户提交的特殊字符
function LQth($thstring)
{        
   $thstring=ereg_replace("&","&amp;",$thstring);
   $thstring=ereg_replace("<","&lt;",$thstring);
   $thstring=ereg_replace(">","&gt;",$thstring);
   $thstring=ereg_replace(chr(13),"<br>",$thstring);
//   $thstring=ereg_replace(chr(32),"&nbsp;",$thstring);
//   $thstring=ereg_replace(chr(9)," &nbsp;&nbsp;&nbsp;&nbsp;",$thstring);
//   $thstring=ereg_replace(chr(39),"&acute;",$thstring);
//   $thstring=ereg_replace(chr(34),"&quot;",$thstring);
   return $thstring;
}


#函数名:cnSubStr 参数: string --字符串 sublen -- 字符串长度 描述:文字截取
function cnSubStr($string,$sublen)  //----------------------文字截取
{
	$string=trim($string);
    if($sublen>=strlen($string))
    {
        return $string;
    }
    $s="";
    for($i=0;$i<$sublen;$i++)
    {
        if(ord($string{$i})>127) 	//处理中文处理
        {
            $s.=$string{$i}.$string{++$i};
            continue;
        }else{
            $s.=$string{$i};
            continue;
        } 
    }
    return $s.".";
}

//递归类别
function LQ_getTree($tnParent,$tnLevel)
{	
    //防止无限递归
	if($tnLevel<=0){  exit();}
	$lcSubId="";
    //获取$parent的全部子节点
	$result = mysql_query("select * from productstype where fid='$tnParent' Order by sortid,typeid desc;");
	//得到每个节点
	while($row=mysql_fetch_array($result))
	{
		$lnindex++;
		//显示的内容
         $lcSubId.=",".$row["typeid"];
		//再次调用这个函数获取这个子节点
		$lcSubId.=LQ_getTree($row['typeid'],$tnLevel-1);
	}
	
	return $lcSubId;

}

//递归类别
function LQ_showTree($tnParent,$tnLevel)
{	
    //防止无限递归
	if($tnLevel<=0){  exit();}
	$lcSubId="";
    //获取$parent的全部子节点
	$result = mysql_query("select * from productstype where typeid='$tnParent' Order by sortid,typeid desc;");
	//得到每个节点
	if(mysql_num_rows($result)>0)
	{
	    $row=mysql_fetch_array($result);
         $lcSubId.="|@1@|".$row["typeid"]."|@2@|".$row["name"];
		//再次调用这个函数获取这个父节点
		$lcSubId.=LQ_showTree($row['fid'],$tnLevel-1);
	}
	
	return $lcSubId;

}

function LQ_showCatePath($tcValue,$tcCaption,$tcUrl)
{
	if(empty($tcValue)){exit();}
	$laArray1=explode("|@1@|",$tcValue);
	//echo array_values($laArray1);
	$laArray2=array_reverse($laArray1) ;
	echo "<a href=\"".$tcUrl."\">".$tcCaption."</a>";
	foreach($laArray2 as $k=>$v)
	{
		$i++;
	  $laRecords=explode("|@2@|",$v);
	  if($i==1){
		echo $laRecords[1]." -> "; 
	  }else{
		echo $laRecords[1]; 
	  }
	}
	
}

function LQ_showCatePath_type($tcValue)
{
	if(empty($tcValue)){return false;}
	$laArray1=explode("|@1@|",$tcValue);
	$laArray2=array_reverse($laArray1) ;
	foreach($laArray2 as $k=>$v)
	{
	  $lnindex++;
	  $laRecords=explode("|@2@|",$v);
	    if($lnindex==1){
		 echo $laRecords[1]; 
		}else{
		 echo ">>".$laRecords[1]; 
		}
	}
	
}


//后台检测url地址栏的合法性
//xid:url后的参数 ; osflg:1、为数字;2、为字符 ;url为 退到登录页面;msg为输出消息。
function chkurl($tcOsflg,$tnID,$tcUrl,$tcMsg)
{
   if($tcOsflg==1){
     if(!preg_match("/^[0-9]{0,10}$/",$tnID)){
	  echo "<script language='javascript'>\n";
	  if($tcMsg)	 echo "alert('".$tcMsg."');\n";
	  echo "location.replace('".$tcUrl."');\n</script>";
	  exit();
	  }
   }elseif($tcOsflg==2){
     if(preg_match("/'+|\"+|\(+|\)+/",$tnID)){
     echo "<script language='javascript'>\n";
	 if($tcMsg)	 echo "alert('".$tcMsg."');\n";
	 echo "location.replace('".$tcUrl."');\n</script>";
      exit();
	 }
   }
}

#函数名:result_toArray 参数: DbTable --数据表 where --条件语句 opt  --- 可选参数 描述:将查询的指定的数据返回为一个数组
function result_toArray($DbTable,$where,$opt="",$link="",$test="")  //-------------------------------读取信息
{
	if($where)$where  = " where ".$where;
	if($test) echo "SELECT * from $DbTable $where $opt"."<br>";
	if($link) $result = mysql_query("SELECT * from $DbTable $where $opt",$link);
	else $result = mysql_query("SELECT * from $DbTable $where $opt");
	while($arr=mysql_fetch_array($result))
	{
		$retArray[]=$arr;
	}
	return $retArray;
}


?>