//增加试题
function AddQuestions($add,$userid,$username){
global $empire,$class_r,$class_zr,$bclassid,$public_r,$dbtbpre,$emod_r;
$add['qclassid']=(int)$add['qclassid'];
$add['qid']=RepPostVar($add['qid']);
$userid=(int)$userid;
$add['title']=returnQnum('question',$add);
$add['answer']=returnQnum('answer',$add);
$add['explains']=returnQnum('explains',$add);
$add['choicetyp'e]=returnQnum('choicetype',$add);
$add['options']=returnAnswer($add);
$add['quotation']=returnQnum('quotation',$add); //题干引用
if($add['isquo']!=1){
$add['quotation']='';
}
if(!$add['title']){
return "题干不能为空!";
}
//操作权限
$doselfinfo=CheckLevel($userid,$username,$add['classid'],"news");
if(!$doselfinfo['doaddinfo'])//增加权限
{
return "无权添加!";
}
$add=DoPostInfoVar($add);//返回变量
$add['checked']=1;
$newstime=empty($add['newstime'])?time():to_time($add['newstime']);
$truetime=time();
$lastdotime=$truetime;
//是否生成
$stb = 1;//存放分表
$ret_r['fields']=',newstime,title,answer,choicetype,qclassid,qid';
$ret_r['values']=",'".$newstime."','".addslashes($add['title'])."','".$add['answer']."','".$add['choicetype']."','".$add['qclassid']."','".$add['qid']."'";
$ret_r['datafields']=',explains,options,quotation';
$ret_r['datavalues']=",'".addslashes($add['explains'])."','".addslashes($add['options'])."','".addslashes($add['quotation'])."'";
//附加链接参数
$addecmscheck=empty($add['checked'])?'&ecmscheck=1':'';
//索引表
$sql=$empire->query("insert into {$dbtbpre}ecms_equestions_index(classid,checked,newstime,truetime,lastdotime,havehtml) values('$add[classid]','$add[checked]','$newstime','$truetime','$lastdotime','$havehtml');");
$id=$empire->lastid();
$pubid=ReturnInfoPubid($add['classid'],$id);
$infotbr=ReturnInfoTbname('equestions',$add['checked'],$stb);
//主表
$infosql=$empire->query("insert into ".$infotbr['tbname']."(id,classid,ttid,onclick,plnum,totaldown,newspath,filename,userid,username,firsttitle,isgood,ispic,istop,isqf,ismember,isurl,truetime,lastdotime,havehtml,groupid,userfen,titlefont,titleurl,stb,fstb,restb,keyboard".$ret_r['fields'].") values('$id','$add[classid]','$add[ttid]','$add[onclick]',0,'$add[totaldown]','$newspath','$filename','$userid','".addslashes($username)."','$add[firsttitle]','$add[isgood]','$add[ispic]','$add[istop]','$isqf',0,'$add[isurl]','$truetime','$lastdotime','$havehtml','$add[groupid]','$add[userfen]','".addslashes($add['my_titlefont'])."','".addslashes($add['titleurl'])."','$stb','$public_r[filedeftb]','$public_r[pldeftb]','".addslashes($add['keyboard'])."'".$ret_r['values'].");");
//副表
$finfosql=$empire->query("insert into ".$infotbr['datatbname']."(id,classid,keyid,dokey,newstempid,closepl,haveaddfen,infotags".$ret_r['datafields'].") values('$id','$add[classid]','$keyid','$add[dokey]','$add[newstempid]','$add[closepl]',0,'".addslashes($add[infotags])."'".$ret_r['datavalues'].");");
//更新栏目信息数
AddClassInfos($add['classid'],'+1','+1',$add['checked']);
//更新新信息数
DoUpdateAddDataNum('info',$class_r[$add['classid']]['tid'],1);
if($sql){
return "success::".$stb.'::'.$id;
}else{
return "数据库出错了!";
}
}
//修改试题
function EditQuestions($add,$userid,$username){
global $empire,$class_r,$class_zr,$bclassid,$public_r,$dbtbpre,$emod_r;
$qclassid=(int)$add['qclassid'];
$qid=RepPostVar($add['qid']);
$userid=(int)$userid;
$id=(int)$add['id'];
$add['title']=returnQnum('question',$add); //题干
$add['answer']=returnQnum('answer',$add); //正确答案
$add['explains']=returnQnum('explains',$add); //解释
$add['choicetype']=returnQnum('choicetype',$add); //题型
$add['options']=returnAnswer($add); //选项
$add['quotation']=returnQnum('quotation',$add); //题干引用
if($add['isquo']!=1){
$add['quotation']='';
}
if(!$add['title'])
{
return "题干不能为空!";
}
//操作权限
$doselfinfo=CheckLevel($userid,$username,$add['classid'],"news");
if(!$doselfinfo['doaddinfo'])//增加权限
{
return "无权添加!";
}
$add=DoPostInfoVar($add);//返回变量
$add['checked']=1;
//是否生成
$stb = (int)$add['stb'];//存放分表
$ret_r['values']="title='".addslashes($add['title'])."',answer='".$add['answer']."',choicetype='".$add['choicetype']."'";
$ret_r['datavalues']="explains='".addslashes($add['explains'])."',options='".addslashes($add['options'])."',quotation='".addslashes($add['quotation'])."'";
$pubid=ReturnInfoPubid($add['classid'],$id);
$infotbr=ReturnInfoTbname('equestions',$add['checked'],$stb);
//主表
$infosql=$empire->query("update ".$infotbr['tbname']." set ".$ret_r['values']." where id='$id' and qclassid='$qclassid' and qid='$qid' ");
//副表
$finfosql=$empire->query("update ".$infotbr['datatbname']." set ".$ret_r['datavalues']." where id='$id'");
if($infosql)
{
return "success::".$stb.'::'.$id;
}
else
{
return "数据库出错了!";
}
}
//删除信息
function DelQuestions($add,$classid,$userid,$username){
global $empire,$class_r,$class_zr,$bclassid,$public_r,$dbtbpre,$emod_r,$adddatar;
$id=(int)$add['id'];
if(!$id)
{
return '请选择信息';
}
$doselfinfo=CheckLevel($userid,$username,$classid,"news");//操作权限
if(!$doselfinfo['dodelinfo'])//删除权限
{
return "无权删除!";
}
$stb = (int)$add['stb'];//存放分表
$infotbr=ReturnInfoTbname('equestions',1,$stb);
$sql=$empire->query("delete from {$dbtbpre}ecms_equestions_index where id='$id'");
$sql=$empire->query("delete from ".$infotbr['tbname']." where id='$id'");
$fsql=$empire->query("delete from ".$infotbr['datatbname']." where id='$id'");
return 'success';
}
不知道能不能发!代码容易被屏蔽 |