<?php
/*******************************************************************
 * 版权协议：2009-2019
 * 版权所有: PHP-北京金南曦网络技术有限公司旗下PHPWMS，PHP商城系统技术支持中心http://www.php188.net，并保留所有权利。 
* PHP商城系统网址: http://www.php188.com
 * PHPWMS系统网址：http://www.phpwms.com
 * 销售电话：010-87875088
 * 销售电话：010-87875188 
*------------------------------------------------------------------
 * 这不是一个完全免费软件！您只能在不用于商业目的的前提下对程序代码进
 * 行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 *------------------------------------------------------------------
 * 文件名称：phpwms.guestbook.php
 * 摘　　要：用户留言
 * 适用范围：PHPWMS 1.0
 * 版　　本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
if(!defined('IN_SYS')) {exit('phpwms');}
class guestbook_WMS extends base{
	protected function init(){
		parent::init();
	}
	function wmsAction(){
		$this->guestbookAction();
	}
	/**
	 * 留言
	 *
	 */
	public function guestbookAction(){
		$url = building_url('member@guestbook', 'guestbook');
		$this->setSeo(array('keywords'=>'会员留言', 'title'=>'会员留言'));
		if($this->isPost()){
			$_SESSION['guestbook'] = $_POST;
			$sitebg = unserialize_deep(get_cache('phpwms_guestbook'));
			$flg = empty($sitebg['isguessbook']) ? true : false;
			$curuser = $this->getCurUser($flg);
			$post = html_encode($_POST);
			// 得到判断验证码是否正确
			if(empty($post['numcode']) || !$this->check_code($post['numcode'])){
				$this->bgmsg('验证码不正确，请重新填写',$url);
			}
			$data['title'] = $post['title'];
			if(empty($data['title'])){
				$this->bgmsg('标题不能为空',$url);
			}
			if(empty($post['content'])){
				$this->bgmsg('内容不能为空',$url);
			}
			$array = explode("\n", $sitebg['search']);
			$array = array_map('trim', $array);
			$array = array_filter($array);
			$data['content'] = str_replace($array, $sitebg['replace'], $post['content']);
			$data['user_name'] = empty($curuser['login_name']) ? '匿名用户' : $curuser['login_name'];
			$data['user_id'] = empty($curuser['id']) ? 0 : $curuser['id'];
			$data['post_time'] = time();
			$data['state'] = 0;
			$msg = $this->db->insert($data, 'user_request') ? '添加成功，请等待管理员回复' : '添加失败';
			$_SESSION['guestbook'] = ''; /*清空session*/
			$this->bgmsg($msg,$url);
		}else{
			$sql = "SELECT COUNT(*) as count FROM ##__user_request WHERE `state` = '1' AND request_type = 'request'";
			$count = $this->db->fetch($sql, true);
			$sql = "SELECT * FROM ##__user_request WHERE `state` = 1 AND request_type = 'request' ORDER BY post_time DESC";
			$result = page_for_db_extend($count['count'], $sql, $url , 10);
			$this->tpl->assign('guestbooks', $result);
			$this->tpl->assign('guestbook_form', $url);
			$this->display('member/guestbook.php');
		}
	}
}
?>