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

/* 管理回复 */
/* 162100源码 - 162100.com */

$text = $err = $text_eval = '';
//处理关键字
function process_input() {
  $str = preg_replace('/[^\x80-\xffa-zA-Z0-9]+/', ' ', $_GET['keyword']); //\u4e00-\u9fa5
  $str = trim($str);
  $str = str_replace(' ','|',$str);
  return $str;
}

//加亮标题中的关键字
function red_keyword_title($str) {
  global $keyword;
  return !empty($keyword) ? @preg_replace('/('.$keyword.')/i','<span class="redword">$1</span>', $str) : $str;
}

//加亮标题中的关键字
function red_keyword_text($str) {
  global $keyword;
  if (preg_match('/('.$keyword.')/i', $str, $matches)) {
    $str = cutstr(strstr((string)$str, (string)$matches[1]), 300);
  }
  return @preg_replace('/('.$keyword.')/i', '<span class="redword">$1</span>', $str);
}

$article_url = $web['url_html_article'] == 1 ? '"article.".$area_mode[get_arearoot($row["area_id"])].".".$row["r_id"].".1.html' : '"article.php?mode=".$area_mode[get_arearoot($row["area_id"])]."&id=".$row["r_id"]."';

$_GET['act'] = @$_GET['act'];
if ($_GET['act'] == 'search') {
  require('inc/function/cutstr.php');

  $keyword = process_input();
  $key = str_replace('|', '%', $keyword);

  if (POWER == 2 || POWER == 3) {
    $out = '您所辖版区的';
    $where_key = ','.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' AS B WHERE A.area_check_reply="0" AND A.text LIKE "%'.$key.'%" AND B.id=A.r_id AND ('.trim(preg_replace('/\((\d+\-\d+)\)/', 'area_id="$1" OR area_id LIKE "$1\_%" OR ', $session[4]), ' OR').')';
  } else {
    $out = '全部';
    $where_key = ','.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' AS B WHERE A.area_check_reply="0" AND A.text LIKE "%'.$key.'%" AND B.id=A.r_id';
  }

  if ($keyword == '') { //检验关键字
    $e = '请输入字、句等有效的查询字符！';
  }
  if (($strlength = strlen($keyword)) && ($strlength > 100 || $strlength < 3)){
    $e = '关键字长度请大于等于3且少于100字符！';
  }
  $text_eval = '$row["text"] = red_keyword_text($row["text"]);';
  $search_r = '搜索结果 - ';

} else {
  if (POWER == 2 || POWER == 3) {
    $out = '您所辖版区的';
    $where_key = ','.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' AS B WHERE A.area_check_reply="0" AND B.id=A.r_id AND ('.trim(preg_replace('/\((\d+\-\d+)\)/', 'area_id="$1" OR area_id LIKE "$1\_%" OR ', $session[4]), ' OR').')';
  } else {
    $out = '全部';
    $where_key = ','.$sql['pref'].''.$sql['data']['承载主题文章的表名'].' AS B WHERE A.area_check_reply="0" AND B.id=A.r_id';
  }
}

$run_bar = '"<a href=\"?post=unity_run&dataname=reply&id[]=".$row["id"]."&limit=del&m=1\" class=\"run_bar\" target=\"lastFrame\">删</a>".(strstr($row["author_ip"], ".") ? "<a href=\"?post=ip&ips=".$row["author_ip"]."&m=1\" class=\"run_bar\" target=\"lastFrame\">屏蔽此IP</a>" : "<a href=\"?get=member&username=".urlencode($row["author_ip"])."\" class=\"run_bar\" target=\"_blank\">管理回复者</a><a href=\"?post=unity_run&dataname=member&id[]=".urlencode($row["author_ip"])."&limit=del\" class=\"run_bar\" title=\"直接删除作者\">×</a>").""';



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

if ($sql['db_err'] == '') {
    $result = @mysql_query('SELECT area_id,area_check_reply,area_index FROM '.$sql['pref'].''.$sql['data']['承载版区分类的表名'].' WHERE area_id REGEXP "^[0-9]+\-[0-9]+$"', $db);
    while ($row = @mysql_fetch_assoc($result)) {
      $area_mode[$row['area_id']] = get_li_mode($row['area_index']);
      unset($row);
    }
    @mysql_free_result($result);

  $result = @mysql_query('SELECT COUNT(A.id) AS total FROM '.$sql['pref'].''.$sql['data']['承载回复评论的表名'].' AS A'.$where_key.'', $db);
  $row = @mysql_fetch_assoc($result);
  $n = abs($row['total']);
  @mysql_free_result($result);
  unset($row);

  require ('inc/function/get_page.php');
@ require ('inc/function/get_date.php'); //时间
    require ('inc/function/cutstr.php');
  if ($n > 0) {
    $p = get_page($n); //页数
    $seek = $web['pagesize'] * ($p-1);
    $result = @mysql_query('SELECT A.id,A.r_id,A.author_ip,A.text,A.date,A.area_check_reply,B.area_id,B.author_ip AS author,B.title,B.date AS d FROM '.$sql['pref'].''.$sql['data']['承载回复评论的表名'].' AS A'.$where_key.' ORDER BY A.id DESC LIMIT '.$seek.','.$web['pagesize'].'', $db);
    while ($row = @mysql_fetch_assoc($result)) {
      eval($text_eval);
        $text .= '
<table width="100%" class="li" id="reply_'.$row['id'].'" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20"><input name="id[]" id="id[]" type="checkbox" class="checkbox" value="'.$row['id'].'" /></td>
    <td>

      <div><span class="column_">于'.$row['author'].' '.$row['d'].'发表的主题<a href="'.eval('return '.$article_url.'";').'" target="_blank"><b>《'.$row['title'].'》</b></a>中</span></div>
      <div class="text">'.cutstr($row['text'], 450).'</div>

  <div class="li_">
<span class="li_update_mark" title="更新"></span> '.(strstr((string)$row['author_ip'], '.') ? '<span title="匿名用户">'.$row['author_ip'].'</span>' : '<a href="user.php?get=card&username='.urlencode($row['author_ip']).'" target="_blank" title="点击查看发布人名片"><img src="inc/images/card.gif" />'.$row['author_ip'].'</a>').'（'.get_date_c($row['date']).'）
     '.eval('return '.$run_bar.';').' 
<a href="'.eval('return '.$article_url.'&reply_id='.$row['id'].'#reply_'.$row['id'].'";').'" target="_blank">查看回复详情&raquo;</a>
     </div>


    </td>
  </tr>
</table>
';

    }
    @mysql_free_result($result);

    $text .= @get_page_foot($n, $web['pagesize'], $p, '?get=reply&act='.$_GET['act'].'&keyword='.$_GET['keyword'].'&p=');

  } else {
    $err .= '暂无记录';
  }
} else {
  $err .= $sql['db_err'];
}

@mysql_close();


?>
<style type="text/css">
<!--
a.run_bar { font-size:12px; margin-left:1px; margin-right:1px; padding:1px; background-color: #999966; font-weight:normal; color: #FFF; }
.li .column_ { border-bottom:1px #999966 solid; }
-->
</style>
<iframe id="lastFrame" name="lastFrame" frameborder="0" marginheight="0" marginwidth="0" style="display:none;"></iframe>
<div class="list_title"><a href="?get=reply" class="list_title_in"><?php echo @$search_r.@$out; ?>回帖列表<span>（<?php echo $n; ?>）</span></a></div>
<form action="?post=unity_run&dataname=reply" method="post" id="manageform">
  <div class="manager_menu"> <a href="javascript:void(0)" onclick="allChoose(true,true);return false;">全选</a> - <a href="javascript:void(0)" onclick="allChoose(true,false);return false;">反选</a> - <a href="javascript:void(0)" onclick="allChoose(false,false);return false;">不选</a> &nbsp;&nbsp;
      <button name="act2" type="button" onclick="chk(this.form,this,'del')"><b>删除</b></button>
    <input type="checkbox" class="checkbox" name="delsendmess" id="delsendmess" value="1" />
    同时发信 |
    <input type="text" id="keyword" name="keyword" style="width:120px;" onfocus="if(this.value=='关键词'){this.value=''}" value="<?php echo @$keyword ? @$_GET['keyword'] : '关键词'; ?>" />
      <button type="button" name="button" onclick="if($('keyword').value!='' && $('keyword').value!='关键词'){location.href='?get=reply&act=search&keyword='+$('keyword').value+'';}"><b>搜索</b></button>
  </div>
  <?php
echo $text, $err;
?>
  <input type="hidden" name="limit" />
</form>
