<?php
/*
乘风下载管理系统
作者QQ：178575
作者Email：yliangcf@163.com
作者网站：http://www.qqcf.com
详细简介：http://www.qqcf.com/cfdown.htm
上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
因为这些内容可能时常更新，就没有放在程序里，请自己上网站查看
*/
?>
<?php 
//以下为公用函数
function AlertRef($AlertStr){
	echo("<!DOCTYPE HTML>
	<link rel='stylesheet' href='images/BeAlert.css'>
	<script src='js/jquery.min.js'></script>
	<script src='js/BeAlert.js'></script>
	<link rel='stylesheet' href='../images/BeAlert.css'>
	<script src='../js/jquery.min.js'></script>
	<script src='../js/BeAlert.js'></script>
	<link rel='stylesheet' href='../../images/BeAlert.css'>
	<script src='../../js/jquery.min.js'></script>
	<script src='../../js/BeAlert.js'></script>
	<script>");

		
	if($AlertStr == ""){
		if(Request.ServerVariables("Http_Referer") != "")
			echo("location.href='".$_SERVER["HTTP_REFERER"]."';");
		else
			echo("location.href='" . HttpPath(5) . "';");
	}else{
		if ($_SERVER["HTTP_REFERER"]!="")
			echo("$(function () { alert('".$AlertStr."','', function () {location.href='".$_SERVER["HTTP_REFERER"]."';}, {type: 'info', confirmButtonText: '确定'});});");
		else
			echo("$(function () { alert('".$AlertStr."','', function () {location.href='" . HttpPath(5) . "';}, {type: 'info', confirmButtonText: '确定'});});");
	}
	
	echo("</script>");
	exit;
} 


function GoBack($Str,$AlertStr){
	if ($Str=="")
	{
		echo("<!DOCTYPE HTML>
		<link rel='stylesheet' href='images/BeAlert.css'>
		<script src='js/jquery.min.js'></script>
		<script src='js/BeAlert.js'></script>
		<link rel='stylesheet' href='../images/BeAlert.css'>
		<script src='../js/jquery.min.js'></script>
		<script src='../js/BeAlert.js'></script>
		<link rel='stylesheet' href='../../images/BeAlert.css'>
		<script src='../../js/jquery.min.js'></script>
		<script src='../../js/BeAlert.js'></script>
		<script>");

		if($AlertStr == "")
			echo("history.go(-1)");
		else
			echo("$(function () { alert('".$AlertStr."','', function () {history.go(-1);}, {type: 'info', confirmButtonText: '确定'});});");

		echo "</script>";
		exit();
	}
	else
	{
		$function_ret=$Str;
	} 

return $function_ret;
} 


function AlertBack($AlertStr,$BackNum){
	echo("<!DOCTYPE HTML>
	<link rel='stylesheet' href='images/BeAlert.css'>
	<script src='js/jquery.min.js'></script>
	<script src='js/BeAlert.js'></script>
	<link rel='stylesheet' href='../images/BeAlert.css'>
	<script src='../js/jquery.min.js'></script>
	<script src='../js/BeAlert.js'></script>
	<link rel='stylesheet' href='../../images/BeAlert.css'>
	<script src='../../js/jquery.min.js'></script>
	<script src='../../js/BeAlert.js'></script>
	<script>");

	if($AlertStr == "")
	 echo("history.go(-".$BackNum.")");
	else
	 echo("$(function () { alert('".$AlertStr."','', function () {history.go(-".$BackNum.");}, {type: 'info', confirmButtonText: '确定'});});");

	echo "</script>";
	exit();
} 


function AlertUrl($AlertStr,$Url){
	echo("<!DOCTYPE HTML>
	<link rel='stylesheet' href='images/BeAlert.css'>
	<script src='js/jquery.min.js'></script>
	<script src='js/BeAlert.js'></script>
	<link rel='stylesheet' href='../images/BeAlert.css'>
	<script src='../js/jquery.min.js'></script>
	<script src='../js/BeAlert.js'></script>
	<link rel='stylesheet' href='../../images/BeAlert.css'>
	<script src='../../js/jquery.min.js'></script>
	<script src='../../js/BeAlert.js'></script>
	<script>");
	
	if($AlertStr == ""){
		if($Url != "")
			echo("location.href='" . $Url . "';");
		else
			echo("location.href='" . HttpPath(5) . "';");
	}else{
		if($Url != "")
			echo("$(function () { alert('".$AlertStr."','', function () {location.href='" . $Url . "';}, {type: 'info', confirmButtonText: '确定'});});");
		else
			echo("$(function () { alert('".$AlertStr."','', function () {location.href='" . HttpPath(5) . "';}, {type: 'info', confirmButtonText: '确定'});});");
	}

	echo "</script>";
	exit();
} 


function AlertClose($AlertStr){
	echo("<!DOCTYPE HTML>
	<link rel='stylesheet' href='images/BeAlert.css'>
	<script src='js/jquery.min.js'></script>
	<script src='js/BeAlert.js'></script>
	<link rel='stylesheet' href='../images/BeAlert.css'>
	<script src='../js/jquery.min.js'></script>
	<script src='../js/BeAlert.js'></script>
	<link rel='stylesheet' href='../../images/BeAlert.css'>
	<script src='../../js/jquery.min.js'></script>
	<script src='../../js/BeAlert.js'></script>
	<script>");
	
	if($AlertStr == "")
	echo("window.close();");
	else
	echo("$(function () { alert('".$AlertStr."','', function () {window.close();;}, {type: 'info', confirmButtonText: '确定'});});");

	echo "</script>";
	exit();
} 

function gotourl($url)
{
  echo "<script>";
  echo "location.href='".$url."';";
  echo "</script>";
  exit;
}

function ChkStr($paravalue,$paratype) //过滤非法字符
{
 $paravalue=isset($paravalue) ? $paravalue : "";
 
 if($paratype==0)
 {
  $inputstr=str_replace("'","''",$paravalue);
 }
 elseif($paratype==1)
 {
  $filterstr="(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
  if (preg_match("/".$filterstr."/is",$paravalue)==1){   
    echo $paravalue."传递的参数类型有错误1！";
    exit;
  }

  $inputstr=str_replace("'","''",$paravalue);
  }
 elseif($paratype==2)
 {
   if($paravalue!=""&&is_numeric($paravalue)==false)
   {
     echo $paravalue."传递的参数类型有错误2！";
     exit;
	}
   else
   { 
     $inputstr=$paravalue;
    }
 }
 elseif($paratype==3)
 {
   if($paravalue!=""&&(strtotime($paravalue)==false||strtotime($paravalue)==-1))
   {
     echo($paravalue."传递的参数类型有错误3！");
     exit;
   }
   else
   { 
    $inputstr=$paravalue;
    }
 }

 return $inputstr;
}


//--获取当前页的网址信息
function HttpPath($assort)
{

  $function_ret=$UrlStr='';
  $HttpTcp=$_SERVER['HTTPS']!= "on"?'http://':"https://";
  $Ser=$_SERVER["SERVER_NAME"];
  $Scr=$_SERVER["SCRIPT_NAME"];
  $Port=$_SERVER["SERVER_PORT"];

  $Scr_2=strrev(substr(strrev($Scr),(strpos(strrev($Scr),"/") ? strpos(strrev($Scr),"/")+1 : 0)-1));
 //http://www.a.com:100/b/c.asp?aa=1&bb=2
 //1.www.a.com
 //2.http://www.a.com:100/b/
 //3.http://www.a.com:100/b/c.asp
 //4.http://www.a.com:100/b/c.asp?aa=1&bb=2
 //5./b/
 //6./b/c.asp
 //7./b/c.asp?aa=1&bb=2
 
  if ($assort==1)  {
    $function_ret=$Ser;
	
  } elseif($assort==2) {
    if ($Port=="80" || $Port=="443")
      $function_ret=$HttpTcp.$Ser.$Scr_2;
      else
      $function_ret=$HttpTcp.$Ser.":".$Port.$Scr_2;
  
  }elseif($assort==3){
    if ($Port=="80" || $Port=="443")
      $function_ret=$HttpTcp.$Ser.$Scr;
      else
      $function_ret=$HttpTcp.$Ser.":".$Port.$Scr;
  
  }elseif($assort==4){
    if ($_SERVER["QUERY_STRING"]!="") $UrlStr="?".$_SERVER["QUERY_STRING"];
    if ($Port=="80" || $Port=="443")
      $function_ret=$HttpTcp.$Ser.$Scr.$UrlStr;
      else
      $function_ret=$HttpTcp.$Ser.":".$Port.$Scr.$UrlStr;
  
  }elseif($assort==5){
  $function_ret=$Scr_2;
  
 }elseif($assort==6){	 
  $function_ret=$Scr;
 
 }elseif($assort==7){
  $function_ret=$Scr.$UrlStr;
 }
 
  return $function_ret;
} 



function PxFilter($px,$pxok)
{
$px=strtolower($px);
$pxok=strtolower($pxok);

$myarray=explode(",",$pxok);

for ($i=0;$i<=count($myarray)-1;$i++){
 if($myarray[$i]==$px)
 {
  $j=1;
 }
}

 if($j<>1) alertback("禁止此类排序",1);
}


//获取分页
function ShowPage($TotalRs,$TotalPage,$Page,$PageUrl,$Px){
if($Px!="") $PageUrl=$PageUrl."&Px=".$Px;

if($TotalRs>0){

if($Page>9){
 $ks=$Page-5;
 $js=$Page+5; 
 if($ks<1){$ks=1;$js=$ks+9;} 
 if($js>intval($TotalPage)){$js=$TotalPage;$ks=$js-9;}
}else{ 
 if(intval($TotalPage)>10){
  $ks=1; $js=10;
 }else{
  $ks=1;$js=$TotalPage;
 } 
}

echo "<div id='fenye' class='fenye'>";
if($Page!=1){
	if($Page==2)//第二页时上一页是首页
	echo("<a href='".$PageUrl."&Page=1' class='prev'>上一页</a> ");
	else
	echo("<a href='".$PageUrl."&Page=".($Page-1)."' class='prev'>上一页</a> ");
 
	echo("<a href='".$PageUrl."&Page=1' class='prev'>首页</a> ");

}else{
	echo("<a href='".$PageUrl."&Page=1' class='prev'>首页</a> ");
}

for ($i=$ks;$i<=$js;$i++){
  if(intval($i)==intval($Page))
   echo("<a href='".$PageUrl."&Page=".$i."' class='curr'>".$i."</a> ");
  else
   echo("<a href='".$PageUrl."&Page=".$i."' class='num'>".$i."</a> ");
}

if(intval($Page)<intval($TotalPage))
 echo("<a href='".$PageUrl."&Page=".$TotalPage."' class='next'>尾页</a> <a href='".$PageUrl."&Page=".($Page+1)."' class='next'>下一页</a>");
else
 echo("<a href='".$PageUrl."&Page=".$TotalPage."' class='next'>尾页</a>");

echo "&nbsp;&nbsp;共".$TotalRs."条记录";

echo "&nbsp;&nbsp;转到第<select id='Page' onChange=\"window.location='".$PageUrl."&Page='+document.getElementById('Page').options[document.getElementById('Page').selectedIndex].value\">";

for ($i=1;$i<=$TotalPage;$i++){
 echo "<option value=".$i;
 if($Page==$i) echo " selected";
 echo ">".$i."</option>";
}
echo "</select>页";
echo "</div>";
echo "<div style='clear:both;'></div>";
}

}

//缩短网址
function shorturl($url){ 
$url=crc32($url); 
$x=sprintf("%u",$url); 

$show=''; 
while($x>0){ 
$s=$x % 62; 
if ($s>35){ 
$s=chr($s+61); 
}elseif($s>9&&$s<=35){ 
$s=chr($s+55); 
} 
$show.=$s; 
$x=floor($x/62); 
}

return sprintf('%06s', $show);//如不足6位长度字符前面以0补足
}

function GetStr($App,$MyStr)
{
  $function_ret="";
  $MyStr_1="|-|".$App."|-|";
  $MyStr_2="";
  $I_Str=0;

  if(strpos(strtolower($MyStr_1),"|-|".strtolower($MyStr)."=")===false){
	 return $function_ret;
  }else{
	 $I_Str=strpos(strtolower($MyStr_1),"|-|".strtolower($MyStr)."=");
  }

 $MyStr_2=substr($MyStr_1,$I_Str+strlen($MyStr)+4);
 $function_ret=substr($MyStr_2,0,strpos($MyStr_2,"|-|"));

 return $function_ret;
}

function GetStrB($App,$MyStr,$SpanNum)
{
  $function_ret="";
  $I_StrB=0;
  $SplitStr="";

  for ($I_StrB=1; $I_StrB<=$SpanNum; $I_StrB=$I_StrB+1)
  {
    $SplitStr=$SplitStr."-";
  }

  $MyStr_1="|".$SplitStr."|".$App."|".$SplitStr."|";
  $MyStr_2="";

  $I_StrB=0;
  if(strpos(strtolower($MyStr_1),"|".$SplitStr."|".strtolower($MyStr)."=")===false)
  {
   return $function_ret;
  }else{
   $I_StrB=strpos(strtolower($MyStr_1),"|".$SplitStr."|".strtolower($MyStr)."=");
  }
  $MyStr_2=substr($MyStr_1,$I_StrB+strlen($MyStr)+3+$SpanNum);  
  $function_ret=substr($MyStr_2,0,strpos($MyStr_2,"|".$SplitStr."|"));
  
  return $function_ret;
}


function GetStrC($App,$MyStr,$SplitStr)
{
  $function_ret="";

  $I=(strpos(strtolower($MyStr_1),$SplitStr.strtolower($MyStr)."=") ? strpos(strtolower($MyStr_1),$SplitStr.strtolower($MyStr)."=")+1 : 0);
  if ($I>0)
  {
    $MyStr_2=substr($MyStr_1,$I+strlen($MyStr)+strlen($SplitStr)+1-1);
    $function_ret=substr($MyStr_2,0,(strpos($MyStr_2,$SplitStr) ? strpos($MyStr_2,$SplitStr)+1 : 0)-1);
  } 

  return $function_ret;
}
