分享:织梦问答模块可以在后台修改问答和答案

时间:2014-07-23

找了很久的修改问答系统的方法,就是站长在网站后台就可以修改问题和答案的方法,现在分享给大家,用的到的好评一下。

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">&nbsp;</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">&nbsp;</td>
<td>&nbsp;</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">&nbsp;</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里面加入
 

<meta name="keywords" content="<?php echo $typeinfo['keywords']?>" />
<meta name="description" content="<?php echo $typeinfo['description']?>" />

10.在question.php第30行加入
if($question['tid2']!=0){
        $myquestiontid=    $question['tid2'];
    }else{
        $myquestiontid=    $question['tid'];
    }
    $myquestiontype=$dsql->getone("select * from `dede_asktype` where id=$myquestiontid");

11.找到//等级上面加入
//上,下一条问题

if($question[tid2]){
$myupdowntype="tid2=$question[tid2]";
}
else{
$myupdowntype="tid=$question[tid]";
}

$mydown= $dsql->getone("SELECT id,title FROM `dede_ask`  WHERE $myupdowntype and status>='0' and id>'$id' order by id asc limit 0,1");
$myup= $dsql->getone("SELECT id,title FROM `dede_ask`  WHERE $myupdowntype and status>='0' and id< '$id' order by id desc limit 0,1");

if($myup){
$myuplink="<a href=/question.php?id=$myup[id]>$myup[title]</a> ";
}
if($mydown){
$mydownlink="<a href=/question.php?id=$mydown[id]>$mydown[title]</a> ";
}

12.在question.htm中加入
<meta name="keywords" content="<?php echo $question['title'].",".$question['keywords'].",".str_replace("_",",",$myquestiontype['title']);?>" />
<meta name="description" content="<?php echo $question['content'].$question['description']?>" />

13.ask_type.htm中加入
<tr>
        <td bgcolor="#FFFFFF">网页title:</td>
        <td bgcolor="#F8FCF1"><textarea name="title"><?php echo $sector['title']; ?></textarea></td>
    </tr>
    <tr>
        <td bgcolor="#FFFFFF">关键字:</td>
        <td bgcolor="#F8FCF1"><textarea name="keywords"><?php echo $sector['keywords']; ?></textarea></td>
    </tr>
    <tr>
        <td bgcolor="#FFFFFF">描述:</td>
        <td bgcolor="#F8FCF1"><textarea name="description"><?php echo $sector['description']; ?></textarea></td>
    </tr>

14.在ask_admin.htm中加入
<link href="http://viscms.blog.163.com/blog/js/thickbox.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="http://viscms.blog.163.com/blog/js/jquery.js"></script>
<script language="javascript" src="http://viscms.blog.163.com/blog/js/thickbox.js"></script>

15.在ask中else if($action == 'delete')上面加入
else if($action == 'search'){
    require_once(DEDEINC.'/datalistcp.class.php');
    if($_POST['selecttype'] =="tid2" ||$_POST['selecttype'] =="uid"||$_POST['selecttype'] =="reward"||$_POST['selecttype'] =="status"){
        $wheresql ="where ".$_POST['selecttype']." = ".$_POST['search']."";

    }else{
    $wheresql ="where ".$_POST['selecttype']." like '%".$_POST['search']."%'";
    }
    $query = "select * from `dede_ask` $wheresql order by id desc";
    updatecount();
    $dlist = new DataListCP();
    $dlist->pageSize = 20;
    $dlist->SetParameter("tid",$tid);
    $dlist->SetParameter("tid2",$tid2);
    $dlist->SetParameter("status",$status);
    $dlist->SetTemplet(DEDEADMIN."/templets/ask_admin.htm");
    $dlist->SetSource($query);
    $dlist->Display();
}

16.在ask_admin.htm中找到,未审核的问题</a></b>加入
<div style=" float:left">
<form method="POST" action="ask_admin.php?action=search">
搜索类型:
<select name="selecttype">
    <option value="tidname">顶层栏目名称</option>
    <option value="tid2">上级栏目号</option>
    <option value="tid2name">上级栏目名称</option>
    <option value="uid">用户号</option>
    <option value="title" selected>标题</option>
    <option value="reward">回答数</option>
    <option value="status">问题状态</option>
    <option value="content">问题包含内容</option>
    <option value="ip">提问者IP</option>
</select>
<input type="text" name="search" style="width:200px;"> <input type="submit" value="提交">
</form>
</div>

对应的地方加入
<td><a href="http://viscms.blog.163.com/blog/modify_ask.php?item=mod_ask&askid=<?php echo $fields['id']; ?>" title="修改问题:">修改问题</a> &nbsp;|&nbsp;
<a href="http://viscms.blog.163.com/blog/modify_ask.php?item=revert&askid=<?php echo $fields['id']; ?>" title="问题回复修改:">回复</a>
</td>

17.在ask_answer.htm中找到未审核的答案</a></b>加入
<div style=" float:left">
<form method="POST" action="ask_answer.php?action=search">
搜索类型:
<select name="selecttype">
    <option value="username">用户名</option>
    <option value="content" selected>回答包含内容</option>
    <option value="ip">回答者IP</option>
</select>
<input type="text" name="search" style="width:200px;"> <input type="submit" value="提交">
</form>
</div>
在ask_answer.php中找到117行加入
else if ($action =="search"){
    CheckPurview('a_Commend,sys_ArcBatch,ask_AllowAll');
    if($_POST['selecttype'] =="username"||$_POST['selecttype'] =="ip"){
        $wheresql ="where ".$_POST['selecttype']." = \"".$_POST['search']."\"";
    }else{
        $wheresql ="where ".$_POST['selecttype']." like '%".$_POST['search']."%'";
    }
    $query = "select * from `dede_askanswer` $wheresql order by id desc";
    updatecount();
    $dlist = new DataListCP();
    $dlist->pageSize = 20;
    $dlist->SetParameter("tid",$tid);
    $dlist->SetParameter("tid2",$tid2);
    $dlist->SetParameter("check",$check);
    $dlist->SetTemplet(DEDEADMIN."/templets/ask_answer.htm");
    $dlist->SetSource($query);
    $dlist->Display();
    exit();
}
 
18.在question.htm中加入
htmlspecialchars_decode($answer['content'])
上一条:完美解决Dede V5.7问答伪静态方法 下一条:最新织梦dedecms模板调用标签大全(适用dedecms5.7)

相关文章

最新文章