<?php
require ('authentication_member.php');
?>
<?php

/* 发表回复提交 */
/* 162100源码 - 162100.com */

/*
if (empty($_GET['mode']) || $_GET['mode'] != 'i') {
  err('<script> alert("只支持i模式！"); </script>');
}
*/
if ($_GET['id'] == '' || !is_numeric($_GET['id'])) {
  err('<script> alert("ID参数为空或错误！"); </script>');
}

if (!isset($sql['db_err'])) {
  db_conn();
}
if ($sql['db_err'] != '') {
  err($sql['db_err']);
}

$result = @mysql_query('SELECT id,area_check,area_id,topdate,reply,author_ip FROM `'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'` WHERE id="'.$_GET['id'].'"', $db);
if (!$row_this = @mysql_fetch_assoc($result)) {
  err('<script> alert("数据库查不到你要回复的文章！可能参数出错或已被删除。"); </script>');
}
if ($row_this['area_check'] == '1' || $row_this['area_check'] == '2') {
  err('<script> alert("文章正提交管理员审核中！暂不允回复评论。"); </script>');
}
@mysql_free_result($result);

//栏目属性
$result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' WHERE area_id="'.get_arearoot($row_this['area_id']).'" LIMIT 1', $db);
if (!$area_power = @mysql_fetch_assoc($result)) {
  err('<script> alert("系统错误：标签参数不合法（找不到该类别根栏目）！请放弃此次发表。"); </script>');
}
@mysql_free_result($result);

//取版区信息
$result = @mysql_query('SELECT id FROM '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' WHERE area_id="'.$row_this['area_id'].'" LIMIT 1', $db);
if (!@mysql_num_rows($result) > 0) {
  err('<script> alert("系统错误：标签参数不合法（找不到该类别）！请放弃此次发表。"); </script>');
}
@mysql_free_result($result);

//过期
if (floatval($area_power['area_expires']) > 0) {
  if ($row_this['topdate'] < gmdate('Y-m-d H:i:s', time() + (floatval($web['time_pos']) * 3600) - floatval($area_power['area_expires']) * 86400)) {
    err('<script> alert("该文时效期已过，回复评论被关闭！"); </script>');
  }
}

/* 身份验证 */
if (POWER >= 1) {
  if (is_numeric($web['reg_to_send']) && $web['reg_to_send'] > 0) {
    $date_diff = ',TIMESTAMPDIFF(SECOND,regdate,DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR)) AS t_diff';
    $date_eval = '
    if ($row_member["t_diff"] < $web["reg_to_send"]) {
      err("<script> alert(\"提交被拒绝！系统设定：新注册成员".$web["reg_to_send"]."秒（".round($web["reg_to_send"] / 3600, 2)."小时）之后才能发表。你还要等".round(($web["reg_to_send"] - $row_member["t_diff"])/ 3600, 2)."小时。\"); </script>");
    }';
  }
  $result = @mysql_query('SELECT power,point,check_reg'.$date_diff.' FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.$session[0].'"', $db);
  if (!$row_member = @mysql_fetch_assoc($result)) {
    err('<script> alert("查无您的档案！您不是合法的注册成员"); </script>');
  }
  @mysql_free_result($result);
  if ($row_member['check_reg'] == '1') {
    err('<script> alert("您的注册尚在审核中！您不是合法的注册成员"); </script>');
  }
  if ($row_member['check_reg'] == '2') {
    err('<script> alert("您的帐户已被管理员移除至黑名单"); </script>');
  }
  if (POWER == 1) { //不计管理员5、4、版主3、2
    eval($date_eval);
    if (strstr($row_member['power'].'_', 'a') || strstr($row_member['power'].'_', 'r')) { //a所有，r回复
      err('<script> alert("提交被拒绝！您已经被限制评论或回复，具体请询问管理员，以获得权限"); </script>');
    }
    if (floatval($area_power['area_power_reply']) > 0 && $row_member['point'] < floatval($area_power['area_power_reply'])) {
      err('<script> alert("提交被拒绝！本类别回复积分需达到'.$area_power['area_power_reply'].'分"); </script>');
    }
  }

} else {

  if (!empty($area_power['area_power_reply'])) {
    err('<script> alert("提交被拒绝！该分类禁止匿名回复！先去注册或登陆，以获得回复权限"); </script>');
  }
/*
  if (!$_COOKIE['regimcode'] || !$_POST['imcode'] || $_POST['imcode'] != $_COOKIE['regimcode']) {
    err('<script> alert("验证码缺失或不符！"); </script>');
  }
*/
  $session[0] = user_ip();
  if (@mysql_num_rows(@mysql_query('SELECT id FROM `'.$sql['pref'].''.$sql['data']['承载上传数据的表名'].'` WHERE title LIKE "'.preg_replace('/(\d+|\*+)$/', '%', $session[0]).'" AND type="ip"', $db)) > 0) {
    err('<script> alert("抱歉，你所处的IP段已被屏蔽，禁止操作"); </script>');
  }

}

/*
//过滤、检测
$content = $_GET['act'] == 'zan' ? '<赞>' : '<拍>';

//检查你是不是支持、反对过了，当天
$result = @mysql_query('SELECT COUNT(id) AS total FROM `'.$sql['pref'].''.$sql['data']['承载回复评论的表名'].'` WHERE r_id="'.$_GET['id'].'" AND author_ip="'.$session[0].'" AND `text`="'.mysql_real_escape_string($content).'" AND `date` LIKE "'.gmdate('Y-m-d', time() + (floatval($web['time_pos']) * 3600)).'%"', $db);

$row = @mysql_fetch_assoc($result);
if (abs($row['total']) > 0) {
  err('<script> alert("今天你已经'.($_GET['act'] == 'zan' ? '赞' : '拍砖').'过了，歇歇吧"); </script>');
}
unset($row);
@mysql_free_result($result);

@mysql_query('INSERT INTO `'.$sql['pref'].''.$sql['data']['承载回复评论的表名'].'` (`text`) values ("")', $db);
$now_id = @mysql_insert_id();

if (!is_numeric($now_id) || $now_id == 0) {
  echo mysql_errno().':'.mysql_error();
  err('<script> alert("插入数据出错！数据没有加入数据库。程序出错"); </script>');
}
@mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载回复评论的表名'].'` SET
`r_id`="'.$_GET['id'].'",
`text`="'.mysql_real_escape_string($content).'",
`date`=DATE_ADD(UTC_TIMESTAMP(), INTERVAL '.floatval($web['time_pos']).' HOUR),
`author_ip`="'.$session[0].'"'.$insert_eval_2.'
WHERE id="'.$now_id.'"', $db);
*/

$cookie_time = time() + floatval($web['time_pos']) * 3600 + $_POST['save_cookie'];
@mysql_query('ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'` ADD COLUMN `zanfan` varchar(16) NOT NULL DEFAULT "0|0"');

if ($_GET['act'] == 'fan') {
  if (isset($_COOKIE['fan'][$_GET['id']])) {
    err('<script> alert("砖你已经拍过了！"); </script>');
  }
  setcookie('fan['.$_GET['id'].']', 1, $cookie_time, '/');
  @mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'` SET zanfan=CONCAT_WS("|", left(zanfan, instr(zanfan, "|") - 1), SUBSTRING(zanfan, instr(zanfan, "|") + 1) + 1) WHERE id="'.$_GET['id'].'"', $db);
} else {
  if (isset($_COOKIE['zan'][$_GET['id']])) {
    err('<script> alert("你已经赞过了！"); </script>');
  }
  setcookie('zan['.$_GET['id'].']', 1, $cookie_time, '/');
  @mysql_query('UPDATE `'.$sql['pref'].''.$sql['data']['承载主题文章的表名'].'` SET zanfan=CONCAT_WS("|", left(zanfan, instr(zanfan, "|") - 1) + 1, SUBSTRING(zanfan, instr(zanfan, "|") + 1)) WHERE id="'.$_GET['id'].'"', $db);
}
//select CONCAT_WS("|", left('1010|0', instr('1010|0', '|') - 1) + 1, SUBSTRING('1010|0', instr('1010|0', '|') + 1));
//select CONCAT_WS("|", left('1010|100', instr('1010|100', '|') - 1), SUBSTRING('1010|100', instr('1010|100', '|') + 1) + 1);




if (@mysql_affected_rows() > 0) {
  @mysql_close();
  err('<script> try { parent.$("'.($_GET['act'] == 'zan' ? 'zan' : 'fan').'").innerHTML ++; } catch (e) {} </script>');
  err('<script> try { parent.$("'.($_GET['act'] == 'zan' ? 'zan' : 'fan').'_o").onclick=function(){return false;}; } catch (e) {} </script>');
} else {
  @mysql_close();
  err('<script> alert("传递出错['.mysql_errno().':'.mysql_error().']。"); </script>');
}


?>