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

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