<?php
define('IN_OUN', true); 
include_once( "./includes/command.php");
include_once( ROOT_PATH."includes/item_set.php"); 
include_once( ROOT_PATH."includes/shopcomm.php"); 
 /* 评论提交 */ 
$strMessage = ''; 
if($_POST[act] == 'install') {
	$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."pravail_product_comms WHERE ip='".$ip."' order by dateadd desc limit 1";
      $row = $oPub->getRow($sql);
	  $dateadd = ($row)?$nowdatedd - $row[dateadd]:31;
	  if($dateadd > 30) {
          $sql = "INSERT INTO " . $pre."pravail_product_comms (praid,prid, descs ,  ip , email ,  dateadd , states , `domain_id` )" .
               "VALUES ('$praid','$_POST[prid]','$_POST[descs]', '".real_ip()."', '$_POST[email]','".gmtime()."', '0','$_SESSION[$un_domain_id]')"; 
          $oPub->query($sql);

		  $strMessage =  "添加成功!";
		  if($_POST[prid] > 0 ) {
             $db_table = $pre.'pravail_producttxt';
             $sql = "UPDATE " . $pre."pravail_producttxt SET comms= comms+ 1 
                   WHERE `prid` =".$prid." and `domain_id`=".$_SESSION[$un_domain_id];
             $oPub->query($sql);
		  }
		} else {
          $strMessage = '30秒后才能继续添加!'; 
		}
	}
	unset($_POST);  
	//评论结束
	if(!empty($strMessage)){  
		if($Aconf['rewrite']){ 
			$strtmp  =  'shop_c-'.$praid.'-0.html';  
		}else{
			$strtmp  =  'shop_c.php?id='.$praid; 
		} 
		echo "<SCRIPT language='javascript'>\nalert('".$strMessage."!!');top.location='".$strtmp."';</script>";
		exit;
	}  
}

/* 评论列表 */
$where_comms = ($Aconf['support'])?" states = 3 ":"  states <> 1 ";
$strWhere = ' WHERE '.$where_comms.' and domain_id='.$_SESSION[$un_domain_id];
$sql = "SELECT count( * ) AS count FROM ".$pre."pravail_product_comms ".$strWhere;
$count = $oPub->getOne($sql);
$Aconf['set_pagenum'] = 30;

$page = new ShowPage;
$page->PageSize = $Aconf['set_pagenum'];
$page->Total = $count;
$pagenew = $page->PageNum(); 
$page->LinkAry = array("id"=>$praid); 
$strOffSet = $page->OffSet();
/* 翻页 */
$rowpra["showpage"] = ($count > $Aconf['set_pagenum'])?$page->ShowLink_num():''; 

$sql = "SELECT email,ip,descs,dateadd  FROM ".$pre."pravail_product_comms ".$strWhere." ORDER BY prcid desc limit ".$strOffSet;
$AsppAll = $oPub->select($sql); 
$n = 1;
while( @list( $k, $v ) = @each( $AsppAll) ) {
    $AsppAll[$k][dateadd] = date("y年n月j日h:i", $v[dateadd]);
    $Aip = explode(".",$v[ip]);
    $AsppAll[$k][ip] = '第'.$n.'楼 IP:'.$Aip[0].'.'.$Aip[1].'.*';
    $AsppAll[$k][nick] = empty($v[name])?'匿名':$v[name];
    $AsppAll[$k][descs] =  clean_html($v[descs]); 
    $n ++ ;
}
$rowpra["pravail_comms"] = $AsppAll;


$Ahome["nowNave"]  = '<A HREF="./">'.$Aconf['web_title'].'首页</A> > <A HREF="'.$rowpra['pravail_url'].'">商家列表</a>><a href="'.$rowpra['shop_url'].'">'.$rowpra[pra_name].'</a>'; 
$Aconf["header_title"] = '评论|'.$rowpra[pra_name].'|'.$Aconf['header_title'];  

$Ahome["pravail"] = $rowpra; unset($rowpra);

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

$cache_id = sprintf('%X', crc32($_SESSION[$un_domain_id].$prid.$_REQUEST[page]));
if (!$smarty->is_cached($Aconf["displayFile"], $cache_id)) {
	assign_template($Aconf); 
	$smarty->assign('home', $Ahome ); 
	$smarty->assign('user_info', $_SESSION );
	unset($Ahome); 
}
$smarty->display($Aconf["displayFile"], $cache_id); 
?> 