<?php
define('IN_OUN', true);
include_once( "./includes/command.php");
include_once( ROOT_PATH."includes/item_set.php");
include_once( ROOT_PATH."includes/ckeditor/ckeditor.php"); 
include_once( ROOT_PATH."ads.php");
/* 产品页显示的模块 */   
$Aconf['header_title'] = $Aweb_url['support'][0]."|".$Aconf["web_title"]; 
/* 留言提交 */
$db_table = $pre."support";
$strMessage = ''; 
if($_POST[act] == 'install'){

    $strMessage = (is_email($_POST[email]))?'':'EMAIL地址错误!'; 
	$descs =  $_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(empty($strMessage)) {
	  $nowdatedd = gmtime();
      $sql = "SELECT dateadd  FROM ".$pre."support WHERE ip='".$ip."' order by dateadd desc limit 1";
      $row = $oPub->selectrow($sql);
	  $dateadd = ($row)?$nowdatedd - $row[dateadd]:31;
	  if($dateadd > 30) {
          $sql = "INSERT INTO " . $pre."support( descs,ip,name,tel,pos,addrs,email,dateadd,states, `domain_id` )" .
           "VALUES ('$descs', '".$ip."','$_POST[name]','$_POST[tel]','$_POST[pos]','$_POST[addrs]', '$_POST[email]','".$nowdatedd."', '0','$_SESSION[$un_domain_id]')"; 
          $oPub->query($sql);
		} else {
          $strMessage = '30秒后才能继续添加!';
		}
	}

	if(!empty($strMessage)){ 
		$pnid = $pnid?$pnid:0;
		if($Aconf['rewrite']){ 
			$strtmp  =  'support.html';  
		}else{
			$strtmp  =  'support.php'; 
		} 
		echo "<SCRIPT language='javascript'>\nalert('".$strMessage."!!');top.location='".$strtmp."';</script>";
		exit;
	}  
	unset($_POST); 
}
/* 留言列表 */
$strWhere = ($Aconf['support'])?" states = 3 ":" states <> 1 ";
$strWhere = ' WHERE '.$strWhere.' AND domain_id='.$_SESSION[$un_domain_id];
$sql = "SELECT count( * ) AS count FROM ".$pre."support".$strWhere;
$row = $oPub->selectrow($sql);
$count = $row['count']; 
$page = new ShowPage; 
$Aconf['set_pagenum'] =10;
$page->PageSize = $Aconf['set_pagenum'];
$page->PHP_SELF =$PHP_SELF;
$page->Total = $count;
$pagenew = $page->PageNum();
$page->LinkAry = array(); 
$strOffSet = $page->OffSet();
/* 翻页 */
$Ahome["showpage"] = ($count > $Aconf['set_pagenum'])?$page->ShowLink_num():''; 

$sql = "SELECT ip,descs,dateadd  FROM ".$pre."support".$strWhere." ORDER BY spid desc limit ".$strOffSet;
$AsppAll = $oPub->select($sql);
$n = 0 ; $count++;
while( @list( $k, $v ) = @each( $AsppAll) ) { 
	$AsppAll[$k][dateadd] = date("y年n月j日h:i", $v[dateadd]);
	$Aip = explode(".",$v[ip]);
	$n ++ ;
	$j = $count - ($pagenew-1) * $Aconf['set_pagenum']-$n;
	$AsppAll[$k][ip] = '第'.$j.'楼 IP:'.$Aip[0].'.'.$Aip[1].'.*';
	$AsppAll[$k][nick] = empty($v[name])?'匿名':$v[name];
	$AsppAll[$k][descs] =  $v[descs];
	
}
$Ahome["support"] =  $AsppAll;
$Ahome["nowNave"]  = '<A HREF="./">首页</A> > '.$Aweb_url['support'][0]; 

if ((DEBUG_MODE & 2) != 2){
    $smarty->caching = true;
}
/* 调用模板 */ 
$cache_id = sprintf('%X', crc32($_SESSION[$un_domain_id].$pagenew));
if (!$smarty->is_cached($Aconf["displayFile"], $cache_id)) {
	assign_template($Aconf); 
	$smarty->assign('home', $Ahome ); 
	$smarty->assign('user_info', $_SESSION );
	create_html_pre('descs');
	unset($Ahome); 
}
$smarty->display($Aconf["displayFile"], $cache_id); 
?>
