找了很久的修改问答系统的方法,就是站长在网站后台就可以修改问题和答案的方法,现在分享给大家,用的到的好评一下。
1.把ask/include/asktype.inc.php复制到dede/inc/里面去
2.修改/dede/ask_type第91行
把$sql = "update `dede_asktype` set name='$name', reid='$reid', disorder='$disorder' where id='$id' ";
改成$sql = "update `dede_asktype` set name='$name', reid='$reid', disorder='$disorder',keywords='$keywords',description='$description',title='$title' where id='$id' ";
现在在asktype表里面新增 keywords, description , title三个字段
3.在dede/新建modify_ask.php文件,代码如下:
<?php
require_once(dirname(__FILE__)."/config.php");
require_once(DEDEINC.'/datalistcp.class.php');
//问题分类
require_once DEDEADMIN.'/inc/asktype.inc.php';
$dlist = new DataListCP();
$sql = "select * from `dede_ask` where id='".intval($askid)."'";
$row = $dsql->GetOne($sql);
if($item == 'mod_ask'){
include(DEDEADMIN."/templets/modify_ask.htm");
}else if($item == 'revert'){
$sql = "select * from `dede_askanswer` where askid='".intval($askid)."'";
$answerArr = $dsql->GetOne($sql);
include(DEDEADMIN."/templets/ask_revert.htm");
}
exit;
?>
4.在dede/ templets/新建modify_ask.htm文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="http://viscms.blog.163.com/blog/img/base.css" rel="stylesheet" type="text/css" />
<title>修改问题</title>
<script language="javascript" src="http://viscms.blog.163.com/blog/js/jquery.js"></script>
<script language="javascript">
function showSub(reid){
$.getJSON("subTypes.php?reid="+reid, function(data){
$('#sctTid2').empty();
$.each(data,function(i,row){
$('#sctTid2').append("<option value='"+row.id+"'>"+ row.name + "</option>");
});
});
}
</script>
</head>
<body>
<div>
<form action="ask_admin.php" method="post" name="form1">
<input type="hidden" value="modify" name="action" />
<input type="hidden" value="<?php echo $row['id'];?>" name="askid" />
<table width="420" height="125" border="0" cellpadding="0" cellspacing="0" style="margin-top:15px;">
<tr height="35">
<td width="103" align="right">提问者ID:</td>
<td width="133"><?php echo $row['id'];?></td>
</tr>
<tr height="35">
<td align="right">所属栏目:</td>
<td><label>
<select name="ClassLevel1" onchange="showSub($(this).val())">
<?php
foreach($asktypes as $t1){
if($t1['reid'] == '0'){
if($row['tid'] == $t1['id']){
$selected = "selected='selected'";
echo "<option value='".$t1['id']."' ".$selected.">".$t1['name']."</option>";
}else{
echo "<option value='".$t1['id']."'>".$t1['name']."</option>";
}
}
}
?>
</select>
</label>
<label>
<select name="ClassLevel2" id="sctTid2">
<?php
foreach($asktypes as $t2){
if($t2['reid'] == $row['tid']){
if($row['tid2'] == $t2['id']){
$selected = "selected='selected'";
echo "<option value='".$t2['id']."' ".$selected.">".$t2['name']."</option>";
}else{
echo "<option value='".$t2['id']."'>".$t2['name']."</option>";
}
}
}
?>
</select>
</label></td>
</tr>
<tr height="35">
<td align="right">提问标题:</td>
<td><input name="title" type="text" size="52" height="25" value="<?php echo $row['title'];?>" /></td>
</tr>
<tr height="35">
<td align="right">补充说明:</td>
<td><textarea name="content" cols="50" rows="6"><?php echo $row['content'];?></textarea></td>
</tr>
<tr height="35">
<td align="right"> </td>
<td><label>
<input type="submit" name="Submit" value="修改" /></label>
<label>
<input name="cancel" type="reset" id="cancel" value="重置" />
</label></td>
</tr>
<tr height="35">
<td align="right"> </td>
<td> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
5.在dede/templets/新建ask_revert文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="http://viscms.blog.163.com/blog/img/base.css" rel="stylesheet" type="text/css" />
<title>回复问题</title>
</head>
<body>
<div>
<form action="ask_admin.php" method="post" name="form1">
<input type="hidden" name="action" value="revert" />
<input type="hidden" name="askid" value="<?php echo $row['id']; ?>" />
<table width="80%" border="1" cellpadding="10" cellspacing="10">
<tr>
<td width="86" align="right">回复ID:</td>
<td width="370">
<input type="hidden" name="answerid" value="<?php if($answerArr['id'] != ''){ echo $answerArr['id'];}else{ echo 0;}?>" />
<?php if($answerArr['id'] != ''){ echo $answerArr['id'];}else{ echo 0;}?></td>
</tr>
<tr>
<td align="right">问题:</td>
<td><strong><font color="#CC00FF"><?php echo $row['title'];?></font></strong></td>
</tr>
<tr>
<td align="right">补充说明:</td>
<td><font color="#0066CC"><?php echo nl2br($row['content']);?></font></td>
</tr>
<tr>
<td align="right">关键词(多个请用,号分隔):</td>
<td>
<input type="text" value="<?php echo $row['keywords'];?>" name='keywords'/>
</td>
</tr>
<tr>
<td align="right">回复内容:</td>
<td>
<?php GetEditor("content",$answerArr['content']); ?>
</td>
</tr>
<tr>
<td align="right"> </td>
<td><label>
<input type="submit" name="Submit" value="提交" />
<input name="cancel" type="reset" id="cancel" value="重填" />
</label></td>
</tr>
</table>
</form>
</div>
</body>
</html>
6.在dede/ask_admin.php第143行加入以下代码
else if($action == 'modify'){ //修改问题
$ClassLevel1 = intval($ClassLevel1);
$ClassLevel2 = intval($ClassLevel2);
if($ClassLevel2 != 0)
{
$where = "id in ($ClassLevel1,$ClassLevel2)";
}else
{
$where = "id='$ClassLevel1'";
}
$query = "select id, name, reid from `dede_asktype` where $where";
$dsql->Execute('me',$query);
while($row = $dsql->getarray())
{
if($row['id'] == $ClassLevel1)
{
$tidname = $row['name'];
$tid = $row['id'];
}elseif($row['id'] == $ClassLevel2 && $row['reid'] == $ClassLevel1)
{
$tid2name = $row['name'];
$tid2 = $row['id'];
}
}
$sql = "update `dede_ask` set title='{$title}',tid='{$tid}',tidname='{$tidname}',tid2='{$tid2}',tid2name='{$tid2name}',content='{$content}' where id='{$askid}'";
$dsql->ExecuteNoneQuery($sql);
//header('location:ask_admin.php');
ShowMsg("问题修改成功!",'ask_admin.php');
exit;
}else if($action == 'revert'){ //回复问题
if($answerid){
$sql = "update `dede_askanswer` set content='{$content}' where id='{$answerid}'";
$dsql->ExecuteNoneQuery($sql);
}else{
$dateline = time();
$sql = "insert into `dede_askanswer`(askid,ifanswer,username,content,dateline,ifcheck) values('{$askid}',1,'一六一医院专家','{$content}','{$dateline}',1)";
$dsql->ExecuteNoneQuery($sql);
}
$keywords = $_POST['keywords'];
$description = $_POST['description'];
//修改问题状态
$sql = "UPDATE `dede_ask` set status='1',replies='1',keywords='{$keywords}',description='$description' where id='{$askid}'";
$dsql->ExecuteNoneQuery($sql);
ShowMsg("问题回复成功!",'ask_admin.php');
exit;
}
7.在ask表中加入以下字段keywords,description,username
8.修改browser.php第35来始的整个if条件包括elseif
if($tid)
{
$dsql->Execute('me',"select * from `dede_asktype` where id='$tid' ");
if(!$typeinfo = $dsql->getarray())
{
showmsgs('browser_notexists','index.php');
exit;
}
$wheresql .= " tid='$tid' ";
$multistr .="tid=$tid";
$tidstr = "tid=$tid";
if($typeinfo['title'] == ''){
$navtitle = $typeinfo['name'];
}else{
$navtitle = $typeinfo['title'];
}
$nav = " $symbols <a href=\"browser.php?tid=$tid\">".$typeinfo['name'].'</a>';
$toptypeinfo = $typeinfo;
}
elseif($tid2)
{
$dsql->Execute('me',"select * from `dede_asktype` where id='$tid2' ");
if(!$typeinfo = $dsql->getarray())
{
showmsgs('browser_notexists','index.php');
exit;
}
$wheresql .= "tid2='$tid2'";
$multistr .="tid2=$tid2";
$tidstr = "tid2=$tid2";
$toptypeinfo = $dsql->getone("select id, name, asknum from `dede_asktype` where id='".$typeinfo['reid']."' limit 1");
if($typeinfo['title'] == ''){
$navtitlestr = $typeinfo['name'];
}else{
$navtitlestr = $typeinfo['title'];
}
$navtitle = $navtitlestr.' '.$toptypeinfo['name'];
$nav = ' '.$symbols.' <a href="browser.php?tid='.$toptypeinfo['id'].'">'.$toptypeinfo['name'].'</a> '.$symbols.' <a href="browser.php?tid2='.$tid2.'">'.$typeinfo['name'].'</a>';
}
9.在所有的browser.htm里面加入