<?php
require ('authentication_manager.php');
?>
<script language="javascript" type="text/javascript">
<!--
function chkIp(form){
  var text=form.ips.value;
  text=text.replace(/^[\r\n]+/,'');
  text=text.replace(/[\r\n]+$/,'');
  text=text.replace(/[\r\n]+/g,"\n");
  text=text.replace(/ /g,'');
  if(!text.match(/\d+\.\d+\.\d+\.(\d+|\*)/)){
    alert('请填有效的IP数据！格式为：*.*.*.*');
    return false;
  }
  var arr=text.split("\n");
  if(arr.length>0){
    for(var i=0; i<arr.length; i++){
	  if(!arr[i].match(/^\d+\.\d+\.\d+\.(\d+|\*)$/)){
        alert('第'+(i+1)+'行请填有效的IP数据！只能数字、.、换行符、*填写。用回车键分开IP，即一行填一个IP');
        return false;
      }
    }
  }
  addSubmitSafe();
  return true;  
}
-->
</script>
  <?php
$text = $err = $where_ev = $search_r = '';
$n = 0;

$_GET['ip'] = @$_GET['ip'];
if ($_GET['ip']) {
  $_GET['ip'] = preg_replace('/[^\d\.]/', '', $_GET['ip']);
  $where_ev = ' title LIKE "'.$_GET['ip'].'%" AND';
  $search_r = '搜索结果 - ';
}

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

if ($sql['db_err'] == '') {
  
  $result = @mysql_query('SELECT COUNT(id) AS total FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE'.$where_ev.' type="ip"', $db);
  $row = @mysql_fetch_assoc($result);
  $n = abs($row['total']);
  @mysql_free_result($result);
  unset($row);

  if ($n > 0) {
    require ('inc/function/get_page.php');
    $p = get_page($n); //页数
    $seek = $web['pagesize'] * ($p-1);
    $result = @mysql_query('SELECT title,date FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE'.$where_ev.' type="ip" ORDER BY id DESC LIMIT '.$seek.','.$web['pagesize'].'', $db);
    while ($row = @mysql_fetch_assoc($result)) {
      $text .='
<div class="li">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td style="text-align:left;"><input name="id[]" id="id[]" type="checkbox" class="checkbox" value="'.$row['id'].'" />
      '.$row['title'].'</td>
      <td width="200">'.$row['date'].'</td>
    </tr>
  </table>
</div>';
      unset($row);
    }
    @mysql_free_result($result);
    $text .= get_page_foot($n, $web['pagesize'], $p, '?get=ip&p=');
  } else {
    $err = 'IP数据为空';
  }


} else {
  $err = $sql['db_err'];
}

?>
  <div class="list_title"><a class="list_title_in"><?php echo $search_r; ?>屏蔽记录<span>（<?php echo $n; ?>）</span></a></div>
  <form action="?post=unity_run&amp;dataname=upload" 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 type="button" name="act" onclick="chk(this.form,this,'del_ip')"><b>删除</b></button>
      <button name="button" type="button" onclick="addSubmitSafe();location.href='?post=unity_run&dataname=upload&limit=clear_ip&id[]=1';"><b>一键清除全部屏蔽</b></button>
      | 搜索IP
      <input name="ip" id="ip" onkeyup="if(!this.value.match(/^[\d\.]+$/)){alert('请输入数字及点');this.value='';}" value="<?php echo $_GET['ip']; ?>" type="text" size="20" />
        <button name="button" type="button" onclick="location.href='?get=ip&amp;ip='+encodeURIComponent($('ip').value)+''"><b>搜索</b></button>
    </div>
    <div class="list_title_">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <th>IP地址</th>
          <th width="200">屏蔽时间</th>
        </tr>
      </table>
    </div>
    <?php echo $text, $err; ?>
    <input type="hidden" name="limit" />
  </form>
  <br />
  <br />
  <form action="?post=ip" method="post" id="manageform2" onsubmit="return chkIp(this)">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="300"><textarea name="ips" id="ips" cols="30" rows="10"></textarea></td>
        <td>添加要屏蔽的IP，如100.200.300.400。一行添一个。<br />
          如要屏蔽IP段请填：100.200.300.*<br />
          <br />
          <br />
          <br />
          <button class="large" type="submit" name="act"><b>提交</b></button>
          <button class="large" type="reset" name="reset"><b>重置</b></button></td>
      </tr>
    </table>
  </form>
  