<?php
InitGP('qid','G');
if($_POST){
  InitGP('action','G');
  InitGP('aid','P');
  switch($action){
    case'delete':
      DB()->delete('faq',"qid='$qid' and aid='$aid'");
      echo'Y';
      break;
    case'delete2':
      DB()->delete('answer',"aid='$aid'");
      DB()->delete('faq',"aid='$aid'");
      echo'Y';
      break;
  }
  exit();
}
theme_header();
$ot->borderA('#content2','box2');
$co=DB()->select('question','content',"qid='$qid'");
$co=strip_tags($co);
ostrlen($co)>20 && $co=osubstr($co,0,20).'...';
$ot->addhead('“'.$co.'”的答案');
function questionNum($rs){
  return DB()->rows('faq',"aid='$rs[aid]'").' <a href="javascript:viewquestion('.$rs['aid'].')">查看</a>';
}
function myBtns($rs){
  return<<<ONEZ
  <a href="javascript:edit($rs[aid])">编辑答案</a>
  <a href="javascript:del($rs[aid])">从此问题中删除</a>
  <a href="javascript:del2($rs[aid])">完全删除</a>
ONEZ;
}
InitGP('keyword','G');
$html=<<<ONEZ
<div style="top:0px;padding:5px 10px;text-align:right;position:relative">
<form action="$PHP_SELF">
<input name="keyword" type="text" class="text f-input" style="width:160px;height:21px" value="$keyword" />
<input type="submit" value="搜索" name="commit" id="submit" class="formbutton"/>
<input name="a" type="hidden" value="$a" />
<input name="b" type="hidden" value="$b" />
<input name="qid" type="hidden" value="$qid" />
</form>
</div>
ONEZ;
$ot->addhtml($html);
$ot->setlist(
  DB()->page('answer','*',"aid in (select aid from $#faq where qid='$qid') and content like '%$keyword%' order by aid desc",20,'?a='.$a.'&keyword='.$keyword.'&qid='.$qid.'&b='.$b),
  'aid',
  array(
    array(
      'label'=>'编号',
      'token'=>'aid',
    ),
    array(
      'label'=>'答案',
      'token'=>'content',
    ),
    array(
      'label'=>'自定义关键词',
      'token'=>'keywords',
    ),
    array(
      'label'=>'优先级',
      'token'=>'asknum',
    ),
    array(
      'label'=>'问题数量',
      'token'=>'questionNum',
      'type'=>'func',
    ),
    array(
      'label'=>'操作',
      'token'=>'myBtns',
      'type'=>'func',
    ),
  )
);
$ot->borderB(1);
$ot->flush();
echo<<<ONEZ
<script type="text/javascript">
function viewquestion(aid){
  window.open('?a=$a&b=question2&aid='+aid,'','');
}
function edit(aid){
  window.open('?a=$a&b=editanswer&qid=$qid&aid='+aid,'','');
}
function del(aid){
  if(confirm('您确定要从此问题中删除这条答案吗？')){
    $.post('?a=$a&b=$b&action=delete&qid=$qid',{aid:aid},function(s){
      if(s=='Y'){
        location.reload();
      }else{
        alert(s);
      }
    });
  }
}
function del2(aid){
  if(confirm('您确定要彻底删除这条答案吗？')){
    $.post('?a=$a&b=$b&action=delete2',{aid:aid},function(s){
      if(s=='Y'){
        location.reload();
      }else{
        alert(s);
      }
    });
  }
}
</script>
ONEZ;
theme_footer();
?>