<?php
InitGP('aid','G');
if($_POST){
  InitGP('action','G');
  InitGP('qid','P');
  switch($action){
    case'delete':
      DB()->delete('faq',"aid='$aid' and qid='$qid'");
      echo'Y';
      break;
    case'delete2':
      DB()->delete('question',"qid='$qid'");
      DB()->delete('faq',"qid='$qid'");
      echo'Y';
      break;
  }
  exit();
}
theme_header();
$ot->borderA('#content2','box2');
$co=DB()->select('answer','content',"aid='$aid'");
$co=strip_tags($co);
ostrlen($co)>20 && $co=osubstr($co,0,20).'...';
$ot->addhead('“'.$co.'”的问题');
function answerNum($rs){
  return DB()->rows('faq',"qid='$rs[qid]'").' <a href="javascript:viewanswer('.$rs['qid'].')">查看</a>';
}
function myBtns($rs){
  return<<<ONEZ
  <a href="javascript:edit($rs[qid])">编辑问题</a>
  <a href="javascript:del($rs[qid])">从此答案中删除</a>
  <a href="javascript:del2($rs[qid])">完全删除</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="aid" type="hidden" value="$aid" />
</form>
</div>
ONEZ;
$ot->addhtml($html);
$ot->setlist(
  DB()->page('question','*',"qid in (select qid from $#faq where aid='$aid') and content like '%$keyword%' order by qid desc",20,'?a='.$a.'&keyword='.$keyword.'&aid='.$aid.'&b='.$b),
  'qid',
  array(
    array(
      'label'=>'编号',
      'token'=>'qid',
    ),
    array(
      'label'=>'问题',
      'token'=>'content',
    ),
    array(
      'label'=>'自定义关键词',
      'token'=>'keywords',
    ),
    array(
      'label'=>'优先级',
      'token'=>'asknum',
    ),
    array(
      'label'=>'答案数量',
      'token'=>'answerNum',
      'type'=>'func',
    ),
    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(qid){
  if(confirm('您确定要从此答案中删除这条问题吗？')){
    $.post('?a=$a&b=$b&action=delete&aid=$aid',{qid:qid},function(s){
      if(s=='Y'){
        location.reload();
      }else{
        alert(s);
      }
    });
  }
}
function del2(qid){
  if(confirm('您确定要彻底删除这条问题吗？')){
    $.post('?a=$a&b=$b&action=delete2',{qid:qid},function(s){
      if(s=='Y'){
        location.reload();
      }else{
        alert(s);
      }
    });
  }
}
</script>
ONEZ;
theme_footer();
?>