<?php
/* 评论提交 用于文章品论*/
$strMessage = '';
if($_POST[act] == 'install' && $arid > 0 ) {
	$descs = clean_html($_POST["descs"]);
	$strMessage .= ($descs == '')?' 评论内容不能为空':'';
	$ip = real_ip();
	$strMessage .= ($ip == '')?'\n ERROR 1,系统错误，不能添加评论':'';
    /* 读取过滤的关键词 start */
    $db_table = $pre."filter";
    $sql = "SELECT * FROM ".$db_table." WHERE states=1 ORDER BY fid ASC LIMIT 1";
    $Anorm = $oPub->selectrow($sql);
	if($Anorm) {
		if($Anorm["ips"]) {
            $pos = strpos($Anorm["ips"], $ip);
            if ($pos !== false) {
                $strMessage .= '\n ERROR 2,不能添加评论！';
			}
		}

		if($Anorm["words"] && !$strMessage) {
			$Awords = explode(",",$Anorm["words"]);
            foreach ($Awords AS $val) {
				if($val) {
				    $pos = strpos($descs, $val);
                    if ($pos !== false) {
                        $strMessage .= '非法关键词,不能添加评论！';
					    break;
			        } 
				}
			}
		}
	}
    /* 读取过滤的关键词 end */ 

    if($strMessage == '') {
	  $nowdatedd = gmtime();
      $sql = "SELECT dateadd  FROM ".$pre."arti_comms WHERE ip='".$ip."' order by dateadd desc limit 1";
      $row = $oPub->selectrow($sql);
	  $dateadd = ($row)?$nowdatedd - $row["dateadd"]:31;
	  if($dateadd > 30) {
		  //coms_type = 1/2/3/4
          $sql = "INSERT INTO ".$pre."arti_comms  (arid,acid,coms_type,name,descs,  ip , email ,  dateadd , states , `domain_id` )" .
               "VALUES ('$arid',$acid,1,'$_POST[name]', '".$_POST["descs"]."', '".real_ip()."', '".$_POST[email]."','".gmtime()."', '0','$_SESSION[$un_domain_id]')"; 
          $oPub->query($sql);

          $sql = "UPDATE ".$pre."artitxt SET comms =comms + 1 
	             WHERE domain_id = ".$_SESSION[$un_domain_id]." and arid = ".$arid;
          $oPub->query($sql);
		  $rowarticle[comms] = $rowarticle[comms] + 1;

          $strMessage =  "评论添加成功!";
		  /* 如果是登陆用户，测记录用户文章 id coms_type = 1/2/3/4 文章/产品/专题/留言*/
		  if ($_SESSION['user_id']) {
              $sql = "SELECT ucid  FROM ".$pre."users_comms 
			          WHERE user_id  = '".$_SESSION['user_id']."'
					  AND coms_type = 1 
					  AND arid = '".$arid."'";
			  $tmp = $oPub->getOne($sql);
              if ( !$tmp ) {				  
                  $sql = "INSERT INTO ".$pre."users_comms (user_id, coms_type ,arid,dateadd,domain_id) VALUES ('".$_SESSION['user_id']."',1, '".$arid."','".gmtime()."','".$_SESSION[$un_domain_id]."')"; 
                  $oPub->query($sql);
			  } else
			  {
                  $sql = "UPDATE ".$pre."users_comms  SET dateadd = '".gmtime()."'  WHERE ucid = '$tmp'";
                  $oPub->query($sql);
			  }
		   }//$_SESSION['user_id']                                      
		} else
		{
          $strMessage = '30秒后才能继续添加评论!';
		}
	}
	unset($_POST);  
}
//评论结束
if(!empty($strMessage)){ 
    $pnid = $pnid?$pnid:0;
	if($Aconf['rewrite']){ 
	 $strtmp  =  'article-'.$arid.'-'.$pnid.'.html';  
	}else{
	 $strtmp  =  'article.php?id='.$arid.'&pnid='.$pnid; 
	} 
	echo "<SCRIPT language='javascript'>\nalert('".$strMessage."!!');top.location='".$strtmp."';</script>";
	exit;
} 
?>
