ecshop商品及文档都有评论的功能,而现在我们需要做一个咨询功能,这样比较正式的渠道来服务客户,参考现有的评论功能简单实现,后期继续扩展。
增加前台展示以及提交表单
1:goods.dwt增加以下代码,以引用咨询相关的模板
<!– #BeginLibraryItem “/library/comments1.lbi” –><!– #EndLibraryItem –>
2.复制/library/comments.lbi更名为comments1.lbi,内容稍微修改下
1
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
2
|
{insert_scripts files='transport.js,utils.js'}
|
3
|
<div id="ECS_COMMENT1"> {* ECSHOP 提醒您:动态载入comments_list1.lbi,显示评论列表和评论表单 *}{insert name='comments1' type=2 id=$id}</div>
|
3./include/lib_insert.php增加函数
3
|
function insert_comments1($arr)
|
5
|
$need_cache = $GLOBALS['smarty']->caching;
|
6
|
$need_compile = $GLOBALS['smarty']->force_compile;
|
8
|
$GLOBALS['smarty']->caching = false;
|
9
|
$GLOBALS['smarty']->force_compile = true;
|
12
|
if ((intval($GLOBALS['_CFG']['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
|
14
|
$GLOBALS['smarty']->assign('enabled_captcha', 1);
|
15
|
$GLOBALS['smarty']->assign('rand', mt_rand());
|
17
|
$GLOBALS['smarty']->assign('username', stripslashes($_SESSION['user_name']));
|
18
|
$GLOBALS['smarty']->assign('email', $_SESSION['email']);
|
19
|
$GLOBALS['smarty']->assign('comment_type', 2);
|
20
|
$GLOBALS['smarty']->assign('id', $arr['id']);
|
21
|
$cmt = assign_comment($arr['id'], $arr['type']);
|
22
|
$GLOBALS['smarty']->assign('comments', $cmt['comments']);
|
23
|
$GLOBALS['smarty']->assign('pager', $cmt['pager']);
|
25
|
$val = $GLOBALS['smarty']->fetch('library/comments_list1.lbi');
|
27
|
$GLOBALS['smarty']->caching = $need_cache;
|
28
|
$GLOBALS['smarty']->force_compile = $need_compile;
|
4.复制/library/comment_list.lbi更名为comment_list1.lbi,内容稍微修改
1
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
5
|
<h3><span class="text">用户咨询</span>({$lang.total}<font class="f1">{$pager.record_count}</font>用户咨询)</h3>
|
7
|
<div class="boxCenterList clearfix" style="height:1%;">
|
9
|
<!-- {if $comments} -->
|
10
|
<!-- {foreach from=$comments item=comment} -->
|
12
|
<font class="f2"><!-- {if $comment.username} -->{$comment.username|escape:html}<!-- {else} -->{$lang.anonymous}<!-- {/if} --></font> <font class="f3">( {$comment.add_time} )</font><br />
|
13
|
<img src="../images/stars{$comment.rank}.gif" alt="{$comment.comment_rank}"/>
|
14
|
<p>{$comment.content}</p>
|
15
|
<!-- {if $comment.re_content} -->
|
16
|
<p><font class="f1">{$lang.admin_username}</font>{$comment.re_content}</p>
|
25
|
<div id="pagebar" class="f_r">
|
26
|
<form name="sel ectPageForm" action="{$smarty.server.PHP_SELF}" method="get">
|
27
|
<!-- {if $pager.styleid eq 0 } -->
|
29
|
{$lang.pager_1}{$pager.record_count}{$lang.pager_2}{$lang.pager_3}{$pager.page_count}{$lang.pager_4} <span> <a href="{$pager.page_first}">{$lang.page_first}</a> <a href="{$pager.page_prev}">{$lang.page_prev}</a> <a href="{$pager.page_next}">{$lang.page_next}</a> <a href="{$pager.page_last}">{$lang.page_last}</a> </span>
|
30
|
<!--{foreach from=$pager.search key=key item=item}-->
|
31
|
<input type="hidden" name="{$key}" value="{$item}" />
|
36
|
<div id="pager" class="pagebar">
|
37
|
<span class="f_l f6" style="margin-right:10px;">{$lang.total} <b>{$pager.record_count}</b> {$lang.user_comment_num}</span>
|
38
|
<!-- {if $pager.page_first} --><a href="{$pager.page_first}">1 ...</a><!-- {/if} -->
|
39
|
<!-- {if $pager.page_prev} --><a class="prev" href="{$pager.page_prev}">{$lang.page_prev}</a><!-- {/if} -->
|
40
|
<!--{foreach from=$pager.page_number key=key item=item}-->
|
41
|
<!-- {if $pager.page eq $key} -->
|
42
|
<span class="page_now">{$key}</span>
|
44
|
<a href="{$item}">[{$key}]</a>
|
47
|
<!-- {if $pager.page_next} --><a class="next" href="{$pager.page_next}">{$lang.page_next}</a><!-- {/if} -->
|
48
|
<!-- {if $pager.page_last} --><a class="last" href="{$pager.page_last}">...{$pager.page_count}</a><!-- {/if} -->
|
49
|
<!-- {if $pager.page_kbd} -->
|
50
|
<!--{foreach from=$pager.search key=key item=item}-->
|
51
|
<input type="hidden" name="{$key}" value="{$item}" />
|
53
|
<kbd style="float:left; margin-left:8px; position:relative; bottom:3px;"><input type="text" name="page" size="3" class="B_blue" /></kbd>
|
59
|
<script type="Text/Javascript" language="JavaScript">
|
62
|
function sel ectPage(sel)
|
71
|
<div class="blank5"></div>
|
73
|
<div class="commentsList">
|
74
|
<form action="javascript:;" onsubmit="submitComment1(this)" method="post"name="commentForm1" id="commentForm1">
|
75
|
<table width="700" border="0" cellspacing="5" cellpadding="0">
|
78
|
<td align="right">E-mail:</td>
|
80
|
<input type="text" name="email" id="email" maxlength="100" value="{$smarty.session.email|escape}" class="inputBorder"/>
|
85
|
<td align="right" valign="top">{$lang.comment_content}:</td>
|
87
|
<textarea name="content" class="inputBorder" style="height:50px; width:560px;"></textarea>
|
88
|
<input type="hidden" name="cmt_type" value="2" />
|
89
|
<input type="hidden" name="id" value="{$id}" />
|
94
|
<!-- 判断是否启用验证码{if $enabled_captcha} -->
|
95
|
<div style="padding-left:15px; text-align:left; float:left;">
|
96
|
{$lang.comment_captcha}:<input type="text" name="captcha" class="inputBorder" style="width:50px; margin-left:5px;"/>
|
97
|
<img src="captcha.php?{$rand}" alt="captcha" class="captcha"onClick="this.src='captcha.php?'+Math.random()">
|
100
|
<input name="" type="submit" value=" " class="f_r" style="border:none; background:url(../images/commentsBnt.gif); width:75px; height:21px; margin-right:8px;">
|
110
|
<div class="blank5"></div>
|
112
|
<script type="text/javascript">
|
114
|
{foreach from=$lang.cmt_lang item=item key=key}
|
115
|
var {$key} = "{$item}";
|
121
|
function submitComment1(frm)
|
123
|
var cmt = new Object;
|
125
|
cmt.email = frm.elements['email'].value;
|
126
|
cmt.content = frm.elements['content'].value;
|
127
|
cmt.type = frm.elements['cmt_type'].value;
|
128
|
cmt.id = frm.elements['id'].value;
|
129
|
cmt.enabled_captcha = frm.elements['enabled_captcha'] ? frm.elements['enabled_captcha'].value : '0';
|
130
|
cmt.captcha = frm.elements['captcha'] ? frm.elements['captcha'].value : '';
|
133
|
if (cmt.email.length > 0)
|
135
|
if (!(Utils.isEmail(cmt.email)))
|
137
|
alert(cmt_error_email);
|
143
|
alert(cmt_empty_email);
|
146
|
if (cmt.content.length == 0)
|
148
|
alert(cmt_empty_content);
|
151
|
if (cmt.enabled_captcha > 0 && cmt.captcha.length == 0 )
|
153
|
alert(captcha_not_null);
|
156
|
Ajax.call('comment1.php', 'cmt=' + cmt.toJSONString(), commentRespone1, 'POST', 'JSON');
|
162
|
function commentRespone1(result)
|
166
|
alert(result.message);
|
168
|
if (result.error == 0)
|
170
|
var layer = document.getElementById('ECS_COMMENT1');
|
173
|
layer.innerHTML = result.content;
|
5.复制/comment.php重命名为comment1.php,内容稍作修改
5
|
* ============================================================================
|
6
|
* 版权所有 2005-2010 上海商派网络科技有限公司,并保留所有权利。
|
7
|
* 网站地址: http://www.ecshop.com;
|
8
|
* ----------------------------------------------------------------------------
|
9
|
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
|
10
|
* 使用;不允许对程序代码以任何形式任何目的的再发布。
|
11
|
* ============================================================================
|
13
|
* $Id: comment.php 17063 2010-03-25 06:35:46Z liuhui $
|
16
|
define('IN_ECS', true);
|
18
|
require(dirname(__FILE__) . '/includes/init.php');
|
19
|
require(ROOT_PATH . 'includes/cls_json.php');
|
21
|
if (!isset($_REQUEST['cmt']) && !isset($_REQUEST['act']))
|
23
|
/* 只有在没有提交评论内容以及没有act的情况下才跳转 */
|
24
|
ecs_header("Location: ./\\n");
|
27
|
$_REQUEST['cmt'] = isset($_REQUEST['cmt']) ? json_str_iconv($_REQUEST['cmt']) : '';
|
30
|
$result = array('error' => 0, 'message' => '', 'content' => '');
|
32
|
if (empty($_REQUEST['act']))
|
38
|
$cmt = $json->decode($_REQUEST['cmt']);
|
40
|
$cmt->id = !empty($cmt->id) ? intval($cmt->id) : 0;
|
41
|
$cmt->type = !empty($cmt->type) ? intval($cmt->type) : 0;
|
43
|
if (empty($cmt) || !isset($cmt->type) || !isset($cmt->id))
|
46
|
$result['message'] = $_LANG['invalid_comments'];
|
48
|
elseif (!is_email($cmt->email))
|
51
|
$result['message'] = $_LANG['error_email'];
|
55
|
if ((intval($_CFG['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)
|
58
|
include_once('includes/cls_captcha.php');
|
60
|
$validator = new captcha();
|
61
|
if (!$validator->check_word($cmt->captcha))
|
64
|
$result['message'] = $_LANG['invalid_captcha'];
|
68
|
$factor = intval($_CFG['comment_factor']);
|
69
|
if ($cmt->type == 0 && $factor > 0)
|
75
|
if ($_SESSION['user_id'] == 0)
|
78
|
$result['message'] = $_LANG['comment_login'];
|
83
|
if ($_SESSION['user_id'] > 0)
|
85
|
$sql = "SELECT o.order_id FROM " . $ecs->table('order_info') . " AS o ".
|
86
|
" WHERE user_id = '" . $_SESSION['user_id'] . "'".
|
87
|
" AND o.order_status = '" . OS_CONFIRMED . "' ".
|
88
|
" AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') ".
|
89
|
" AND (o.shipping_status = '" . SS_SHIPPED ."' OR o.shipping_status = '" . SS_RECEIVED . "') ".
|
92
|
$tmp = $db->getOne($sql);
|
96
|
$result['message'] = $_LANG['comment_custom'];
|
101
|
$result['error'] = 1;
|