<?php

/*

'**************************************************************************************************

' 软件名称: 黑色幻想舞曲管理系统CMS2.0

' 版本编号: hshxsdj 2.0

' 官方网站: http://www..hshxs.com

' 官方论坛：http://bbs.hshxs.com

' 版权所有: 黑色幻想开发团队    噬己翼(QQ:532917920)

' 郑重声明:

'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；

'    2、黑色幻想网络事业部保留此软件的法律追究权利

'**************************************************************************************************

*/

header("Content-type: text/html;charset=gb2312");

include "../include/conn.php";

include "../include/function.php";

include "../include/userset.php";

if(!eregi($_SERVER['SERVER_NAME'],$_SERVER['HTTP_REFERER'])){exit();}

$action=SafeRequest("action","post","zr");

switch($action){

	case 'main':

		main();

		break;

	case 'add':

		add();

		break;

	default:

		main();

	}



function add(){

	global $db;

	$S_Name=SafeRequest("names","post","filter");

	$S_Content=SafeRequest("content","post","filter");

	$S_Score=SafeRequest("score","post","filter");

	$S_Codes=SafeRequest("codes","post","filter");

	$S_IP=$_SERVER['REMOTE_ADDR'];

	$S_IP=str_encode($S_IP);

	$S_SystemID=SafeRequest("types","post","filter");

	$S_VID=SafeRequest("id","post","filter");

	if(function_exists("mb_convert_encoding")){

		$S_Name=filter(mb_convert_encoding($S_Name,"GBK","UTF-8"));

		$S_Content=filter(mb_convert_encoding($S_Content,"GBK","UTF-8"));

		}

	else{

		$S_Name = filter(iconv( "UTF-8", "GBK//IGNORE" , $S_Name));

		$S_Content = filter(iconv( "UTF-8", "GBK//IGNORE" , $S_Content));

		}	

	$S_AddTime=date('Y-m-d H:i:s');

	if(Syc_Check=="1"){

		$S_Check=1;

		}

	else{

		$S_Check=0;

		}	

	if(Syc_Star=="0"){

		die("close");

		}

	if(defined('S_Ccode') && S_Ccode=='1'){	

		if($_SESSION["codes"]!=$S_Codes)  die("codeerr");//验证码错误

	}

	if(strlen($S_Name)>Syc_NameLen){

		die("namelenerr");//用户名过长

		}	

	if(strlen($S_Content)>Syc_Comment){

		die("contentlenerr");//内容过长

		}

	if(DateDiff($_SESSION['reviewtime'],date("Y-m-d H:i:s"))<16){

		die("timeerror");

		}	

	$sql="Insert s_review (S_Name,S_Content,S_UserIP,S_DateID,S_SystemID,S_Score,S_Check,S_AddTime) values ('".$S_Name."','".$S_Content."','".$S_IP."',".$S_VID.",".$S_SystemID.",".$S_Score.",".$S_Check.",'".$S_AddTime."')";

	//die($sql);

	if($db->query($sql)){

		$_SESSION['reviewtime']=date("Y-m-d H:i:s");

			if(Syc_Check=='1'){

				echo "checkok";

				}

			else{

				echo "ok";

				}	

			

		}

			

	}



function main(){

	global $db;

	$S_ID=SafeRequest("S_ID","post");

	$types=SafeRequest("types","post");

	if(Syc_Check=='1'){

		$sql="select * from  s_review  where S_DateID=".$S_ID." and S_SystemID=".$types." and S_Check=0 order by S_ID desc";

		}

	else{

		$sql="select * from  s_review  where S_DateID=".$S_ID." and S_SystemID=".$types." order by S_ID desc";

		}	

	

	$Arr=getpagerow2($sql,Syc_Count);//sql,每页显示条数

	$result=$db->query($Arr[2]);

	$recount=$db->num_rows($db->query($sql));//统计总分

	$total=$db->query($sql);

	$ts=0;

	if($total){

		while($totalscore=$db->fetch_array($total)){

				$ts=$ts+$totalscore['S_Score'];

			}

		}

		

	if($recount=="0"){

?>

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" >

  <tr>

    <td height="30" colspan="2" align="center"  style="border-left:1px solid #F3F3F3; border-top:1px solid #F3F3F3; border-bottom:1px solid #F3F3F3;border-right:1px solid #F3F3F3;font-size:13px "><strong>该片暂无评论，快来抢沙发吧！</strong></td>

  </tr>

</table>

<?php		

		}

	else{

		if($result){

			$bgcolorArr=array("#D66103","#512DBD","#780E1A","#C5A200","#DA4912","#530752","#C5A200","#512DBD","#D66103","#530752");



?>



<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" >

<tr>

    <td colspan="2"  style="border-top:1px solid #F3F3F3;font-size:12px; " height="35" align="left">&nbsp;共<strong style='font-size:18px';><?php echo $recount?></strong>位网友参与评论&nbsp;&nbsp;&nbsp;&nbsp;平均分数：<strong style='font-size:18px';><?php echo round($ts/$recount,2)?></strong>&nbsp;分</td>

  </tr>

</table>



<?php			$i=$recount-($Arr[3]-1)*(Syc_Count);

			while ($row = $db ->fetch_array($result)){				

?>

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" >

<tr>

<td width="80%" height="30" align="left"  style="border-left:1px solid #F3F3F3; border-top:1px solid #F3F3F3;font-size:12px;"><strong><font style='font-size:12px;color:<?php echo $bgcolorArr[rand(0,9)];?>;' \>&nbsp;<?php echo $row['S_Name']?></font>&nbsp;&nbsp;&nbsp;</strong>评分：<font style='font-size:15px;color:red;'><?php echo $row['S_Score']?></font>&nbsp;分&nbsp;&nbsp;发表于&nbsp;<?php echo $row['S_AddTime']?></td>

<td width="20%" align="right" style="border-right:1px solid #F3F3F3; border-top:1px solid #F3F3F3;font-size:12px;color:<?php echo $bgcolorArr[rand(0,9)];?>;"><?php if($i==1){echo "沙发";}elseif($i==2){echo "板凳";}elseif($i==3){echo "地板";}else{echo "第".$i."楼";}?>&nbsp;</td>

  </tr>

  <tr>

 <td colspan="2"  style="border-left:1px solid #F3F3F3; border-top:1px solid #F3F3F3; border-bottom:1px solid #F3F3F3;border-right:1px solid #F3F3F3;font-size:12px;padding:12px 12px 12px 12px; " height="30" align="left"><?php echo str_decode(showfaces($row['S_Content']));?></td>

</tr>

</table>

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td height="10"></td></tr></table>

<?php			

			$i=$i-1;

			}

		}

?>



<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" >

<tr>

    <td colspan="2"  style="border-bottom:1px solid #F3F3F3;font-size:12px; " height="10" align="left"><?php echo $Arr[0]?></td>

  </tr>

</table>

<?php		

	}

?>

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td height="10"></td></tr></table>

<form name="form1" action="" method="post">

<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center" style="border-left:1px solid #F3F3F3; border-top:1px solid #F3F3F3; border-bottom:1px solid #F3F3F3;border-right:1px solid #F3F3F3; ">

<tr>

	<td style="font-size:12px;">&nbsp;您的网名：

      <input name="syccom_user" id="syccom_user" style="background:#fffff9;border:1px #eaeaea solid;"  type="text" value="<?php 

if(isset($_COOKIE['s_name'])){

	$S_Name=$_COOKIE['s_name'];

		   echo $S_Name;

	  }else{

		   echo Syc_Name;

		  }

	  ?>" class="text" size=13/>

&nbsp;<font color="#FF0000">＊</font>&nbsp; 评论分数：

<input type="radio" name="score" id="score" value="1" />

1分

<input type="radio" name="score" id="score" value="2" />

2分

<input type="radio" name="score" id="score" value="3" />

3分

<input type="radio" name="score" id="score" value="4" />

4分

<input type="radio" name="score" id="score" value="5" checked="checked"/>

5分

<font color=red>

<div id="msg_syccms_connment" style="margin-top:15px;"></div></font></td>

</tr>

<tr>

 <td>&nbsp;<img src="<?php echo S_SitePath?>images/faces/1.gif" onclick='insertTags("[S","]","1")' alt="沙发"/>

<img src="<?php echo S_SitePath?>images/faces/2.gif" onclick='insertTags("[S","]","2")' alt="板凳"/>

<img src="<?php echo S_SitePath?>images/faces/3.gif"  onclick='insertTags("[S","]","3")' alt="我顶"/>

<img src="<?php echo S_SitePath?>images/faces/4.gif"  onclick='insertTags("[S","]","4")' alt="太强啦"/>

<img src="<?php echo S_SitePath?>images/faces/5.gif"  onclick='insertTags("[S","]","5")' alt="拍砖"/>

<img src="<?php echo S_SitePath?>images/faces/6.gif"  onclick='insertTags("[S","]","6")' alt="微笑"/>

<img src="<?php echo S_SitePath?>images/faces/7.gif"  onclick='insertTags("[S","]","7")' alt="哇噻"/>

<img src="<?php echo S_SitePath?>images/faces/8.gif"  onclick='insertTags("[S","]","8")' alt="做鬼脸"/>

<img src="<?php echo S_SitePath?>images/faces/9.gif"  onclick='insertTags("[S","]","9")' alt="偷笑"/>

<img src="<?php echo S_SitePath?>images/faces/10.gif"  onclick='insertTags("[S","]","10")' alt="郁闷"/>

<img src="<?php echo S_SitePath?>images/faces/11.gif" onclick='insertTags("[S","]","11")' alt="我汗"/>

<img src="<?php echo S_SitePath?>images/faces/12.gif"  onclick='insertTags("[S","]","12")' alt="哇" /></td>

</tr>

<tr>

	<td align="center"><textarea name="comment_content" id="comment_content" wrap="virtual" rows=6 style="width:99%;background:#fffff9;border:1px #eaeaea solid;" class="text"></textarea></td>

</tr>

<tr>

	<td style=" font-size:12px;"><input type="hidden" id="Syc_VID" value="<?php echo $S_ID?>"><input type="hidden" id="types" value="<?php echo $types?>">

    <?php  if( defined('S_Ccode') && S_Ccode=='1'){?>

	&nbsp;验证码：

	  <input type="text" size="4" id="codes" name="codes" style="background:#fffff9;border:1px #eaeaea solid;" onclick="javascript:document.getElementById('imgcodes').style.display=''" >&nbsp;<img src="<?php echo S_SitePath?>include/code.php?<?php echo rand();?>"   id="imgcodes" style="display:none">&nbsp;

      <?php 

	}

	  ?>

	  <input name="comm_addbtn" type="button" id="comm_addbtn" onclick="check_sub()" value="发表评论"  style=" background:url(<?php echo S_SitePath?>images/common/btn.gif); border:0px solid #CCC; color:#39F; height:31px; width:96px; border-left:0px solid red; margin-top:5px; font-weight:bold; "/> 

</td>

</tr>

<tr>

	<td height="10"></td>

</tr>

</table>

</form>



<?php

}



function getpagerow2($mysql,$pagesize){

	global $db;

	$url=$_SERVER["QUERY_STRING"];

	if(stristr($url,'&pages')){

		$url=preg_replace('/&pages=([\S]+?)$/','',$url);

	}

	if(stristr($url,'pages')){

		$url=preg_replace('/pages=([\S]+?)$/','',$url);

	}

	if(IsNul($url)){$url.="&";}



	$pages=SafeRequest("pages","post");

	$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.= "页数".$pagejs."&nbsp;";

 





	$str.= "<a href='#' onclick='showlist(1)'>第一页</a>";

	if($pagejs<=10){

  		for($i=1;$i<=$pagejs;$i++){

   			$str.="<a href='#' onclick='showlist(".$i.")'>".$i."</a>&nbsp;";

 	 	}

	}

	else{

 		if($pages>=12){

 			for($i=$pages-5;$i<=$pages+6;$i++){

   				if($i<=$pagejs){

   					$str.="<a href='#' onclick='showlist(".$i.")'>".$i."</a>&nbsp;";

    			}

  			}

  			if($i<=$pagejs){ 

    			$str.="....";

	    		$str.="<a href='#' onclick='showlist(".$pagejs.")'>".$pagejs."</a>&nbsp;";

   			}

   		}

  		else{

  			for($i=1;$i<=12;$i++){

    			$str.="<a href='#' onclick='showlist(".$i.")'>".$i."</a>&nbsp;";

 		} 

 				if($i<=$pagejs){ 

      				$str.="....";

	  				$str.="<a href='#' onclick='showlist(".$pagejs.")'>".$pagejs."</a>&nbsp;";

    			}

 		 }

	}



	$str.="<a href='#' onclick='showlist(".($pages+1).")'>下一页</a>&nbsp;";

	$str.="<a  href='#' onclick='showlist(".$pagejs.")'>最后页</a>&nbsp;";

	$str.="转<input type=text size=4 name='gopage' style='margin-top:4px;' value='".$pages."'/>&nbsp;<a style='cursor:pointer;' onclick='showlist(gopage.value)'>GO>></a>&nbsp;";

	//echo $str;

	//echo $result;

	 while ($row = $db -> fetch_array($result) ){

  		//echo $row['S_ID']."&nbsp;";

	 }

	 $arr=array($str,$result,$sql,$pages);

	 return $arr;

}



function filter($str){

	$KeyArr=explode(',',Syc_GSQL);

	for($i=0;$i<count($KeyArr);$i++){

		$str=ReplaceStr($str,$KeyArr[$i],"***");

		}

		return $str;

	}

	

function showfaces($Str){

	$Str=ReplaceStr($Str,"[S1]","<img src=".S_SitePath."images/faces/1.gif>");

	$Str=ReplaceStr($Str,"[S2]","<img src=".S_SitePath."images/faces/2.gif>");

	$Str=ReplaceStr($Str,"[S3]","<img src=".S_SitePath."images/faces/3.gif>");

	$Str=ReplaceStr($Str,"[S4]","<img src=".S_SitePath."images/faces/4.gif>");

	$Str=ReplaceStr($Str,"[S5]","<img src=".S_SitePath."images/faces/5.gif>");

	$Str=ReplaceStr($Str,"[S6]","<img src=".S_SitePath."images/faces/6.gif>");

	$Str=ReplaceStr($Str,"[S7]","<img src=".S_SitePath."images/faces/7.gif>");

	$Str=ReplaceStr($Str,"[S8]","<img src=".S_SitePath."images/faces/8.gif>");

	$Str=ReplaceStr($Str,"[S9]","<img src=".S_SitePath."images/faces/9.gif>");

	$Str=ReplaceStr($Str,"[S10]","<img src=".S_SitePath."images/faces/10.gif>");

	$Str=ReplaceStr($Str,"[S11]","<img src=".S_SitePath."images/faces/11.gif>");

	$Str=ReplaceStr($Str,"[S12]","<img src=".S_SitePath."images/faces/12.gif>");

	return $Str;

	}	

?>