<?php
InitGP('hid','G');
if($_POST){
  InitGP('action','G');
  InitGP('hid','P');
  switch($action){
    case'delete':
      $uid=DB()->select('history','uid',"hid='$hid'");
      DB()->delete('ufield',"uid='$uid'");
      DB()->delete('history',"hid='$hid'");
      DB()->delete('message',"hid='$hid'");
      DB()->delete('book',"hid='$hid'");
      echo'Y';
      break;
  }
  exit();
}
theme_header();
$ot->borderA('#content2','box2');
$ot->addhead('对话记录');
function myBtns($rs){
  global $a,$b;
  $hid=$rs['hid'];
  $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[hid])">删除</a>
ONEZ;
}
function asknum($rs){
  return DB()->rows('message',"hid='$rs[hid]' and ifusr='1'");
}
function failnum($rs){
  return DB()->rows('message',"hid='$rs[hid]' and ifusr='0' and aid='0'");
}
$ot->setlist(
  DB()->page('history','*',"1 order by hid desc",20,'?a='.$a.'&b='.$b),
  'hid',
  array(
    array(
      'label'=>'用户编号',
      'token'=>'uid',
    ),
    array(
      'label'=>'提问',
      'token'=>'asknum',
      'type'=>'func',
    ),
    array(
      'label'=>'失败',
      'token'=>'failnum',
      'type'=>'func',
    ),
    array(
      'label'=>'首次访问时间',
      'token'=>'firsttime',
      'type'=>'date',
    ),
    array(
      'label'=>'最近访问时间',
      'token'=>'lasttime',
      'type'=>'date',
    ),
    array(
      'label'=>'首次访问IP',
      'token'=>'firstip',
    ),
    array(
      'label'=>'最近访问IP',
      'token'=>'lastip',
    ),
    array(
      'label'=>'操作',
      'token'=>'myBtns',
      'type'=>'func',
    ),
  )
);
$ot->borderB(1);
$ot->flush();
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(hid){
  if(confirm('您确定要从删除这条记录吗？')){
    $.post('?a=$a&b=$b&action=delete',{hid:hid},function(s){
      if(s=='Y'){
        location.reload();
      }else{
        alert(s);
      }
    });
  }
}
</script>
ONEZ;
theme_footer();
?>