<?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.commnet.php
 * 摘　　要：文章评论
 * 适用范围：PHPWMS 1.0
 * 版　　本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
if(!defined('IN_SYS')) {exit('phpwms');}
class comment_WMS extends base {
	protected function init(){
		parent::init();
	}
	public function wmsAction(){
		$this->commentAction();
	}
	/**
	 * 文章评论
	 *
	 */
	public function commentAction(){
		/*得到文章id 好 查询标题等信息*/
		$this->setSeo(array('keywords'=>'评论', 'title'=>'评论'));
		$cid = to_int($this->_parseItem[0]);
		$url = building_url('member@comment', 'comment', array($cid));
		$article_url = building_url('content', '', array($cid));
		if(empty($cid)){
			$this->bgmsg('参数错误');
		}
		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);
			}
			if(empty($post['content'])){
				$this->bgmsg('内容不能为空',$url);
			}
			$array = explode("\n", $sitebg['search']);
			$array = array_map('trim', $array);
			$array = array_filter($array);
			$data['title'] = str_replace($array, $sitebg['replace'], $post['title']);
			$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;
			$data['ip'] = get_ip();
			$data['c_id'] = $cid;
			$data['request_type'] = 'comment';
			$guest_book_set = unserialize_deep(get_cache(array('phpwms_guestbook')));
			//若$guest_book_set['is_need_check'] 为1表示显示
			if($guest_book_set['is_need_check']=='1'){
				$data['hide'] = '1';
			}
			$msgs = $guest_book_set['is_need_check']=='1'?'添加成功,等候管理员审核!':'添加成功';
			$msg = $this->db->insert($data, 'user_request') ? $msgs : '添加失败';
			$this->bgmsg($msg,$url);
		}else{
			$sql = "SELECT long_title FROM ##__contents WHERE c_id = '$cid' LIMIT 0,1 ";
			$article = $this->db->fetch($sql, true);
			if(empty($article)){
				$this->bgmsg('无可用数据',$article_url);
			}
			$guest_book_set = unserialize_deep(get_cache(array('phpwms_guestbook')));
			//若$guest_book_set['is_need_check'] 为1表示显示
			$ANDD = $guest_book_set['is_need_check']=='1'?"  AND `hide`='0'  ":'';
			$sql = "SELECT COUNT(*) as count FROM ##__user_request WHERE request_type = 'comment' AND c_id = '$cid' $ANDD";
			$count = $this->db->fetch($sql, true);
			$sql = "SELECT * FROM ##__user_request WHERE  request_type = 'comment' AND c_id = '$cid' $ANDD ORDER BY post_time DESC";
			$result = page_for_db_extend($count['count'], $sql, $url , 10);
			$this->tpl->assign('comments', $result);
			$this->tpl->assign('comment_from', $url);
			$this->tpl->assign('article_long_title', $article['long_title']);
			$this->tpl->assign('article_detail',$article_url);
			$this->display('member/comment.php');
		}
	}
}
?>