<?php
InitGP('aid','G');
if($_POST){
  InitGP('action','G');
  InitGP('qid','P');
  switch($action){
    case'cancel':
      DB()->update('question',array('isdefault'=>'0'),"qid='$qid'");
      echo'Y';
      break;
  }
  exit();
}
theme_header();
$ot->borderA('#content2','box2');
$ot->addhead('默认问题');
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:cancel($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" />
</form>
</div>
ONEZ;
$ot->addhtml($html);
$ot->setlist(
  DB()->page('question','*',"isdefault='1' and content like '%$keyword%' order by qid desc",20,'?a='.$a.'&keyword='.$keyword.'&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 cancel(qid){
  $.post('?a=$a&b=$b&action=cancel',{qid:qid},function(s){
    if(s=='Y'){
      location.reload();
    }else{
      alert(s);
    }
  });
}
</script>
ONEZ;
theme_footer();
?>