<?php
	@ini_set('display_errors','0');
	error_reporting (E_ALL & ~E_NOTICE);
	define('DIRCMS_ROOT', str_replace("\\", '/',substr(dirname(__FILE__),0,-7)));
	include DIRCMS_ROOT.'include/common.inc.php';
	$id=intval($contentid);
	if(!$id)exit('Bad request!');
	session_start();
	if($do_submit)
	{
		if($_SESSION['checkcode']!=$chkcode || !$_SESSION['checkcode'])showmsg('验证码不正确!');
		if($authkey!=md5(AUTH_KEY.$catid.$contentid))showmsg('错误的请求!',$DIRCMS['site_url']);
		$_userid=$_userid?$_userid:0;
		$_username=$_username?$_username:'游客';
		$comment=array_map('htmlspecialchars',$comment);
		$t=$comment['content'];
		unset($comment);
		$comment['content']=$t;
		$comment['contentid']=$id;
		$comment['catid']=intval($catid);
		$comment['addtime']=TIME;
		$comment['ip']=IP;
		$comment['addtime']=TIME;
		$comment['userface']=$_userid?$_facephoto:'images/nophoto.gif';
		$comment['userid']=$_userid;
		$comment['status']=$_userid?1:0;
		$comment['score']=intval($score);
		$comment['username']=$_username;//print_r($comment);exit();
		$db->insert(DB_PRE.'comment',$comment);
		$db->query("UPDATE `".DB_PRE."content` SET `".DB_PRE."content`.`comments`=`".DB_PRE."content`.`comments`+1 WHERE `".DB_PRE."content`.`id`={$id}",true);
		if($_userid)
		{
			showmsg('评论成功!',$DIRCMS['site_url'].'comment/index.php?contentid='.$id);
		}
		else
		{
			showmsg('评论成功，需要等待管理员审核后才能显示!',$DIRCMS['site_url'].'comment/index.php?contentid='.$id);
		}
	}
	else
	{
		$template='comment_index';
		$contentid=intval($contentid);
		if(!$contentid)showmsg('错误的请求!',$DIRCMS['site_url']);
		require DIRCMS_ROOT.'/include/admin/content.class.php';
		$c=new content();
		$r=$c->get($id,0,0,true);
		if(!$r)showmsg('错误的请求!',$DIRCMS['site_url']);
		if(!$r['iscomment'])showmsg('该评论已关闭!',$DIRCMS['site_url']);
		$catid=$r['catid'];
		require_once(DIRCMS_ROOT.'include/list.class.php');
		$l=new dircmslist();
		$where="`status`=1 AND `contentid`=".intval($contentid);
		$orderby="support DESC";
		$page=max(isset($page)?intval($page):1,1);
		$head['title']='评论-'.$r['title'];
		$title=$r['title'];
		$url=$r['url'];
		include template($template);
	}
?>