<?php
/*******************************************************************
 * 版权协议：2009-2019
 * 版权所有: PHP-北京金南曦网络技术有限公司旗下PHPWMS，PHP商城系统技术支持中心http://www.php188.net，并保留所有权利。 
* PHP商城系统网址: http://www.php188.com
 * PHPWMS系统网址：http://www.phpwms.com
 * 销售电话：010-87875088
 * 销售电话：010-87875188 
*------------------------------------------------------------------
 * 这不是一个完全免费软件！您只能在不用于商业目的的前提下对程序代码进
 * 行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 *------------------------------------------------------------------
 * 文件名称：admin_guestbook.php
 * 摘　　要：用户留言及评论
 * 适用范围：PHPWMS 1.0
 * 版　　本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
if(!defined('IN_SYS'))exit('access die');
if (!getAdminPri('8101')) {
	exit(NO_AUTH_LOGIN);
}

$do		= trim($_REQUEST['do']);
$tpl -> assign("do",$do);
$tpl -> assign("curpage",abs(intval($_GET['page'])));
$pn  = '客户留言管理';
if (!getAdminPri('8101')) { //判断是否有权限
	print "<script>alert('非常抱歉，你没有权限操作！');</script>";exit;
}
if ($do=='list' || $do == '') { 
	$sql = "SELECT COUNT(*) as count FROM ##__user_request ORDER BY `id` limit 0,1";
	$count = $db->fetch($sql, true);
	$sql = "SELECT qq,request_type, email,book.id, book.user_name, book.title, book.state, book.post_time,book.hide
	 FROM ##__user_request as book LEFT JOIN ##__user_info as user ON user.id = book.user_id  ORDER BY post_time DESC";
	$result = page_for_db_extend($count['count'], $sql, '?action=guestbook&do=list', 15);
	$tpl->assign('result', $result);
} else if ($do=="del") {  //删除留言
	$gb_listid = $_REQUEST['gbid'];
	if(is_array($gb_listid)){
		$gb_listid = array_filter($gb_listid);
		$gbid = '';
		foreach ($gb_listid as $id){
			$gbid .= $id .',';
		}
		$gbid = substr($gbid, 0, -1);
	}else{
		$gbid = abs(intval($gb_listid));
	}
	if(empty($gbid)){
		$sp -> bgmsg('请选择 要删除的留言','?action=guestbook&do=list&page=' . $_GET['page']);
	}
	$sql = "DELETE FROM ##__user_request WHERE `id` IN ($gbid)";
	$msg = $db->query($sql) ? '恭喜你，删除留言操作成功！' : '非常抱歉，删除操作失败！';
	$sp -> bgmsg($msg,'admincp.php?action=guestbook&do=list&page=' . $_GET['page']);
} else if ($do =='reply') {
	$gbid = abs(intval(trim($_POST['gbid'])));
	$url = '?action=guestbook&do=list&page=' . $_GET['page'];
	if(empty($gbid)){
		$sp -> bgmsg('请您选择正确回复用户留言',$url);
	}
	$data['admin_content'] =  html_encode($_POST['admin_content']);
	if(empty($data['admin_content'])){
		$sp -> bgmsg('回复的内容不能为空',$url);
	}
	$data['back_time'] = time();
	$data['state'] = '1';
	$data['hide'] = $_POST['is_hide']=='1'?'0':'1';
	$data['admin_name'] = $_SESSION['admin_user'];
	$msg = $db->update($data, 'user_request', array('id'=>$gbid)) ? '恭喜你，回复留言操作成功' : '非常抱歉，回复留言操作失败！';
	$sp -> bgmsg($msg,$url);
}elseif ($do == 'detail'){
	$pn = '留言详情';
	$gbid = abs(intval(trim($_GET['gbid'])));
	$url = '?action=guestbook&do=list&page=' . $_GET['page'];
	if(empty($gbid)){
		$sp -> bgmsg('请选择正确的用户留言',$url);
	}
	$sql = "SELECT * FROM ##__user_request WHERE `id` = $gbid";
	$result = $db->fetch($sql, true);
	if(empty($result)){
		$sp -> bgmsg('没有此留言',$url);
	}
	$tpl->assign('result', $result);
}

$tpl -> assign("admin_nav",shownav($pn));
$tpl -> display('guestbook_list.tpl');
?>
