<?php
InitGP(array('qid','aid','b'),'G');
function save_add(){
  global $aid;
  if(!$aid)return;
  DB()->replace('faq',array(
    'qid'=>DB()->select('question','qid',"1 order by qid desc"),
    'aid'=>$aid,
  ));
}
$ot->save('question','qid',array(
    'date'=>array('addtime','updatetime'),
    'b'=>substr($b,4),
  )
);

theme_header();
$ot->borderA('#content2','box2');
if(!$qid){
  $ot->addhead('添加新问题');
  $answer='';
  if(!$aid){
    $aid=$_SESSION['answer'];
  }
  if($aid){
    $answer=DB()->select('answer','content',"aid='$aid'");
  }
  $ot->addinput('对应答案','answer',$answer ? $answer : '<font color="gray">无</font>','html',0,'');
}else{
  !gettable('question',"qid='$qid'") && jump('error','您要编辑的问题不存在','?a=faq&b=question');
  $ot->addhead('编辑问题');
}
$ot->addinput('问题','content',$content,'textarea',1,'',array('style'=>'width:400px'));
$ot->addinput('自定义关键词','keywords',$keywords,'textarea',0,'',array('style'=>'width:400px'));
$ot->addinput('优先级','asknum',(int)$asknum,'text',1,'Number',array('tip'=>'可手动修改此处的数值，从而获得优先选择的机会'));
$ot->addinput('','aid',$aid,'name');
if(!$qid){
  $ot->addinput('','addtime','0','hidden',1);
  $ot->addinput('','updatetime','0','hidden',1);
  $ot->addinput('','action','add','name');
  $ot->setform('添加');
}else{
  $ot->addinput('','updatetime','0','hidden',1);
  $ot->addinput('','action','edit','name');
  $ot->setform('保存');
}
$ot->borderB(1);
$ot->flush();
theme_footer();
?>