<?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");

$pages=CS_Request('pages');
$ac=CS_Request('ac');
$sid=CS_Request('sid');
$did=CS_Request('did');
$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_AddTime=date('Y-m-d H:i:s');
                if(empty($did)||empty($sid)){
                        exit('Err_000');//参数错误!
                }
                if(isset($_COOKIE["cs_name"])){
                      $CS_User=$_COOKIE["cs_name"];
                }else{
			exit("Err_100");//没有登入
                }
                if(empty($content)){
			exit("Err_101");//内容为空
                }	
		if(strlen($content)>200){
			exit("Err_102");//内容过长
		}
		if(DateDiff($_SESSION['gbooktime'],date("Y-m-d H:i:s"))<30){
			exit("Err_103"); //时间太短
		}	
		$sql="Insert ".Getdbname('pl')." (CS_User,CS_Content,CS_DID,CS_Ip,CS_SID,CS_AddTime) values ('".$CS_User."','".$content."',".$did.",'".$CS_IP."',".$sid.",'".$CS_AddTime."')";
		if($db->query($sql)){
			$_SESSION['gbooktime']=date("Y-m-d H:i:s"); 
			exit("Err_104");
		}else{
			exit("Err_105");
                }
}else{

if(empty($did)||empty($sid)) exit('参数错误!');

	$sql="select * from ".Getdbname('pl')."  where cs_did=".$did." and cs_sid=".$sid." order by CS_ID desc";
		$Arr=getpagerow2($sql,CS_PlNum,$pages,$did,$sid);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$recount=$db->num_rows($result);
?>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" style="border:#ccc solid 1px;font-size:13px;" >
  <tr>
    <td height="30" style="background-color:#FCFCFC; border-bottom:1px solid #ccc;"><strong>网友评论 (共有 <?php echo $recount?> 个评论)</strong></td>
  </tr>
<?php
		if($recount=="0"){
			echo "<tr><td height='50' align='center'><strong>暂无评论，快来抢沙发吧！</strong></td></tr>";
		}else{
		if($result){
			while ($row = $db ->fetch_array($result)){	
?>
  <tr>
    <td width="100%" style="border-bottom: 1px dotted #ccc;PADDING-top:5px;PADDING-bottom:5px;PADDING-right:5px;PADDING-left:5px;"><table width="98%" border="0"><tr>
        <td width='52' valign="top"><a href="<?php echo userlink('index',getuser('uid',$row['CS_User']))?>" target="_blank"><img border="0" height="48" width="48" src="<?php echo getuser('pic',$row['CS_User'])?>" /></a></td>
        <td valign="top" style="PADDING-left:10px;"><a style="text-decoration:none;" href="<?php echo userlink('index',getuser('uid',$row['CS_User']))?>" target="_blank"><b><?php echo $row['CS_User']?></b></a>&nbsp;<font style="font-size:13px;color:#777;"><?php echo $row['CS_AddTime']?> &nbsp;&nbsp;<a href="###" onclick="Pladdhf('回复@<?php echo $row['CS_User']?>@:');">回复</a><br/>
             <font style="line-height:12pt;font-size:13px;color:#333;"><?php echo facehtml(stripslashes(html_entity_decode($row['CS_Content'])))?></font>
        </td>
       </tr></table>
    </td>
  </tr>

<?php
				}
			}
?>
  <tr><td height="10"></td></tr>
  <tr><td height="30"><?php echo $Arr[0];?></td></tr>
<?php } ?>
  <tr><td height="10"></td></tr>
  <tr>
    <td height="30" style="PADDING-left:5px;background-color:#FCFCFC;border-top:1px solid #ccc;"><strong><a style="text-decoration:none;" href="###" onclick="faceadd('biaoqing');" id="faces">插入表情</a></strong></td>
  </tr>
  <tr id="biaoqing" style="display:none">
    <td width="300" style="border:#ccc solid 1px;" height="25">
    <?php
    	for($i=1;$i<=30;$i++){
              echo "<img src=\"/public/faces/".$i.".gif\" onclick=\"insertsmilie('[em:".$i."]')\" />&nbsp;";
        }
    ?>
    </td>
 </tr>
<?php if(isset($_COOKIE["cs_name"])){ ?>
  <tr>
    <td align="center"><textarea name="cscms_content" id="cscms_content" wrap="virtual" rows=6 style="width:98%;background:#fffff9;border:1px #eaeaea solid;overflow: hidden;" class="text"></textarea></td>
  </tr><input type=hidden value="<?php echo $did?>" name="did" id="did"><input type=hidden value="<?php echo $sid?>" name="sid" id="sid">
  <tr>
    <td align="right"><input name="comm_addbtn" type="button" id="comm_addbtn" onclick="pladd()" value="发表评论"  style=" background:url(<?php echo CS_WebPath?>public/images/btn.gif); border:0px solid #CCC; color:#39F; height:31px; width:96px; border-left:0px solid red; margin-top:5px; font-weight:bold; "/> &nbsp;&nbsp;</td>
  </tr>
<?php }else{ ?>
  <tr>
    <td height="100" style="border:#ccc solid 1px;font-size:13px;background-color:#fcfcfc;font-size:14px;" align="center">你需要登录后才可以评论  <b><a href="<?php echo CS_WebPath?>user/login.php" target="_blank">登陆</a> <a href="<?php echo CS_WebPath?>user/reg.php" target="_blank">注册</a></b></td>
  </tr>
<?php } ?>
  <tr><td height="10"></td></tr>
</table>
<?php					
	
}
	
function getpagerow2($mysql,$pagesize,$pages,$did,$sid){
	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=\"getpllist('1','".$did."','$sid');\">第一页</a>";
	if($pagejs<=10){
  		for($i=1;$i<=$pagejs;$i++){
   			$str.="<a href='javascript:;' onclick=\"getpllist('".$i."','".$did."','$sid');\">".$i."</a>&nbsp;";
 	 	}
	}
	else{
 		if($pages>=12){
 			for($i=$pages-5;$i<=$pages+6;$i++){
   				if($i<=$pagejs){
   					$str.="<a href='javascript:;' onclick=\"getpllist('".$i."','".$did."','$sid');\">".$i."</a>&nbsp;";
    			}
  			}
  			if($i<=$pagejs){ 
    			$str.="....";
	    		$str.="<a href='javascript:;' onclick=\"getpllist('".$pagejs."','".$did."','$sid');\">".$pagejs."</a>&nbsp;";
   			}
   		}
  		else{
  			for($i=1;$i<=12;$i++){
    			$str.="<a href='javascript:;' onclick=\"getpllist('".$i."','".$did."','$sid');\">".$i."</a>&nbsp;";
 		} 
 				if($i<=$pagejs){ 
      				$str.="....";
	  			$str.="<a href='javascript:;' onclick=\"getpllist('".$pagejs."','".$did."','$sid');\">".$pagejs."</a>&nbsp;";
    			}
 		 }
	}

	$str.="<a href='javascript:;' onclick=\"getpllist('".($pages+1)."','".$did."','$sid');\">下一页</a>&nbsp;";
	$str.="<a  href='javascript:;' onclick=\"getpllist('".$pagejs."','".$did."','$sid');\">最后页</a>&nbsp;";
	$str.="转<input type=text size=4 name='gopage' style='margin-top:4px;' value='".$pages."'/>&nbsp;<a style='cursor:pointer;' onclick='getpllist(gopage.value,'".$did."','$sid')'>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;
}
	
?>
