<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache");
if(!@eregi($_SERVER['SERVER_NAME'],$_SERVER['HTTP_REFERER'])){exit('QQ:848769359');}
include_once("../lib/cs_conn.php");
include_once("../lib/cs_common.php");
@header("Content-type: text/html;charset=utf-8");
$pages=CS_Request('pages');
$ac=CS_Request('ac');
$name=CS_Request('name');
$content=filter(CS_Request('content'));
$content=iconv("gb2312","utf-8",$content);
global $db;

if($ac=='add'){
		//php获取ip的算法
		$CS_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
		$CS_IP = ($CS_IP) ? $CS_IP : $_SERVER["REMOTE_ADDR"]; 
		$CS_Usera="csdjcms";
		$CS_AddTime=date('Y-m-d H:i:s');

                if(CS_BookFun==1){
			exit("Err_000");//留言关闭
                }
                if(empty($name)){
			exit("Err_100");//用户名为空
                }
		if(strlen($name)>20){
			exit("Err_101");//用户名过长
		}
                if(empty($content)){
			exit("Err_102");//内容为空
                }	
		if(strlen($content)>200){
			exit("Err_103");//内容过长
		}
		if(DateDiff($_SESSION['gbooktime'],date("Y-m-d H:i:s"))<30){
			exit("Err_104"); //时间太短
		}	
		$sql="Insert ".Getdbname('gbook')." (CS_Usera,CS_Userb,CS_Neir,CS_Ip,CS_CID,CS_AddTime) values ('".$CS_Usera."','".$name."','".$content."','".$CS_IP."',1,'".$CS_AddTime."')";
		if($db->query($sql)){
			$_SESSION['gbooktime']=date("Y-m-d H:i:s"); 
			exit("Err_105");
		}else{
			exit("Err_106");
                }
}else{

	if(CS_BookFun==1){
		exit("站长已经关闭留言！");//留言关闭
	}
	$sql="select * from ".Getdbname('gbook')."  where cs_usera='csdjcms' and cs_cid=1 order by CS_ID desc";
		$Arr=getpagerow2($sql,CS_BookNum,$pages);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$recount=$db->num_rows($result);
		if($recount=="0"){
			echo "<div style='width:100%; border:1px solid #B5D6E6; margin-top:10px; height:30px; font-size:12px; line-height:30px;'>&nbsp;Sorry!暂无留言,请留言吧！！</div>";
		}else{
		if($result){
			while ($row = $db ->fetch_array($result)){	
				if($row['CS_FID']!="0" && trim($row['CS_Hfneir'])!=""){
?>
<div style="width:99.8%; border:1px solid #B5D6E6; margin:0 auto;margin-top:10px;" ><div style="width:100%; height:30px; line-height:30px; font-size:12px; background:#EEF7FE">
	<div style="width:50%; float:left;  color:#185691;">&nbsp;<strong><?php echo $row['CS_Userb']?></strong>&nbsp;&nbsp;IP：<?php echo $row['CS_Ip']?></div>
    <div style="width:48%; float:left;text-align:right; font-size:12px;">发表于:<font color=""red""><?php echo $row['CS_AddTime']?></font></div>
    </div>
    <div style="width:95%; margin:0 auto; height:50px;font-size:12px; line-height:25px;">&nbsp;&nbsp;<?php echo $row['CS_Neir']?></div>
    <div style="width:95%; margin:0 auto; height:20px;font-size:12px; line-height:20px; color:red;">&nbsp;&nbsp;站长回复：</div>
    <div style="width:95%; margin:0 auto; color:red; height:30px;font-size:12px; line-height:20px">&nbsp;&nbsp;<?php echo $row['CS_Hfneir']?></div></div>
<?php					
				}else{					
?>				
		<div style="width:99.8%; border:1px solid #B5D6E6;margin-top:10px;">
        	<div style="width:100%; height:30px; line-height:30px; font-size:12px; background:#EEF7FE">
            	<div style="width:50%; float:left;  color:#185691;">&nbsp;<strong><?php echo $row['CS_Userb']?></strong>&nbsp;IP:<?php echo $row['CS_Ip']?></div>
                <div style="width:48%; float:left;text-align:right; font-size:12px;">发表于：<font color=red><?php echo $row['CS_AddTime']?></font></div>
             </div>
            <div style="width:95%; margin:0 auto; height:80px;font-size:12px; line-height:25px;">&nbsp;&nbsp;<?php echo $row['CS_Neir']?></div>
      </div>		

<?php
				}
			}
?>
            <div style=" font-size:12px;"><?php echo $Arr[0];?>&nbsp;</div>
<?php			
		}
	}		
	
}
	
function getpagerow2($mysql,$pagesize,$pages){
	global $db;
	$pagesok=$pagesize;//每页显示记录数
        if (!isset($pages)||$pages==""||!is_numeric($pages)||$pages<=0){
             $pages=1;
	}
  	$sqlstr=$mysql;
  	$res=$db -> query($sqlstr);
 	$nums= $db -> num_rows($res);
	if($nums==0){
		$pagejs=1;
	}else{
		$pagejs=ceil($nums/$pagesok);//总页数
	}	
 	$str="总<font color=red>".$nums."</font>条记录&nbsp;";
    
    if($pages>$pagejs){
     $pages=$pagejs;
    }
  
    $sql=$sqlstr." LIMIT ".$pagesok*($pages-1).",".$pagesok;
	$str.="当前<font color=red>".$pages."/</font>".$pagejs."页&nbsp;";                                                              ;
	$result = $db -> query($sql);
 
	$str.= "<a href='javascript:;' onclick='getbooklist(1)'>第一页</a>";
	if($pagejs<=10){
  		for($i=1;$i<=$pagejs;$i++){
   			$str.="<a href='javascript:;' onclick='getbooklist(".$i.")'>".$i."</a>&nbsp;";
 	 	}
	}
	else{
 		if($pages>=12){
 			for($i=$pages-5;$i<=$pages+6;$i++){
   				if($i<=$pagejs){
   					$str.="<a href='javascript:;' onclick='getbooklist(".$i.")'>".$i."</a>&nbsp;";
    			}
  			}
  			if($i<=$pagejs){ 
    			$str.="....";
	    		$str.="<a href='javascript:;' onclick='getbooklist(".$pagejs.")'>".$pagejs."</a>&nbsp;";
   			}
   		}
  		else{
  			for($i=1;$i<=12;$i++){
    			$str.="<a href='javascript:;' onclick='getbooklist(".$i.")'>".$i."</a>&nbsp;";
 		} 
 				if($i<=$pagejs){ 
      				$str.="....";
	  			$str.="<a href='javascript:;' onclick='getbooklist(".$pagejs.")'>".$pagejs."</a>&nbsp;";
    			}
 		 }
	}

	$str.="<a href='javascript:;' onclick='getbooklist(".($pages+1).")'>下一页</a>&nbsp;";
	$str.="<a  href='javascript:;' onclick='getbooklist(".$pagejs.")'>最后页</a>&nbsp;";
	$str.="转<input type=text size=4 name='gopage' style='margin-top:4px;' value='".$pages."'/>&nbsp;<a style='cursor:pointer;' onclick='getbooklist(gopage.value)'>GO>></a>&nbsp;";
	 while ($row = $db -> fetch_array($result) ){
	 }
	 $arr=array($str,$result,$sql);
	 return $arr;
}

function filter($str){
	$KeyArr=explode(',','http://,www,胡锦涛,温家宝,尻,屌,操你,干死你,贱人,狗娘,婊子,表子,靠你,叉你,叉死,插你,插死,干你,干死,日你,日死,鸡巴,睾丸,包皮,龟头,屄,赑,妣,肏,奶子,奶头,阴毛,阴道,阴茎,叫床,强奸,爱液,性高潮,做爱,性交,口交,肛交,3P');
	for($i=0;$i<count($KeyArr);$i++){
		$str=CS_ReplaceStr($str,$KeyArr[$i],"**");
	}
	return $str;
}
	
?>

