<?php
InitGP('bid','G');
if($_POST){
  InitGP('action','G');
  InitGP('bid','P');
  switch($action){
    case'delete':
      DB()->delete('book',"bid='$bid'");
      echo'Y';
      break;
    case'delete2':
      InitGP('bids','P');
      if($bids)DB()->delete('book',"bid in ($bids)");
      echo'Y';
      break;
    case'delete3':
      DB()->delete('book',"");
      echo'Y';
      break;
  }
  exit();
}
theme_header();
$ot->borderA('#content2','box2');
$ot->addhead('未知提问');
$bids=array();
function myBtns($rs){
  global $a,$b,$bids;
  $hid=$rs['hid'];
  $bids[]=$rs['bid'];
  $uid=DB()->select('history','uid',"hid='$hid'");
  return<<<ONEZ
  <a href="?a=$a&b=viewhistory&hid=$hid">完整记录</a>
  <a href="?a=$a&b=userinfo&uid=$uid">用户资料</a>
  <a href="javascript:del($rs[bid])">删除</a>
ONEZ;
}
$ot->setlist(
  DB()->page('book','*',"1 order by bid desc",20,'?a='.$a.'&b='.$b),
  'bid',
  array(
    array(
      'label'=>'提问',
      'token'=>'caption',
    ),
    array(
      'label'=>'提问时间',
      'token'=>'time',
      'type'=>'date',
    ),
    array(
      'label'=>'提问者IP',
      'token'=>'ip',
    ),
    array(
      'label'=>'操作',
      'token'=>'myBtns',
      'type'=>'func',
    ),
  )
);
$html=<<<ONEZ
<div class="act">
  <input type="button" value="删除当前页记录" name="commit" class="formbutton" onclick="del2()"/>
  <input type="button" value="清空所有记录" name="commit" class="formbutton" onclick="del3()"/>
</div>

ONEZ;
$ot->addhtml($html);
$ot->borderB(1);
$ot->flush();
$bids=implode(',',$bids);
echo<<<ONEZ

<script type="text/javascript">
function viewanswer(qid){
  window.open('?a=$a&b=answer2&qid='+qid,'','');
}
function edit(qid){
  window.open('?a=$a&b=editquestion&aid=$aid&qid='+qid,'','');
}
function del(bid){
  if(confirm('您确定要从删除这条记录吗？')){
    $.post('?a=$a&b=$b&action=delete',{bid:bid},function(s){
      if(s=='Y'){
        location.reload();
      }else{
        alert(s);
      }
    });
  }
}
function del2(){
  if(confirm('您确定要从删除当前页记录吗？')){
    $.post('?a=$a&b=$b&action=delete2',{bids:'$bids'},function(s){
      if(s=='Y'){
        location.reload();
      }else{
        alert(s);
      }
    });
  }
}
function del3(){
  if(confirm('您确定要从清空所有记录吗？')){
    $.post('?a=$a&b=$b&action=delete3',{bid:'all'},function(s){
      if(s=='Y'){
        location.reload();
      }else{
        alert(s);
      }
    });
  }
}
</script>
ONEZ;
theme_footer();
?>