<?php
/**
 *----------------------------------------------------------------------------*
 * 版权所有 2010-2016 HuCart.COM，并保留所有权利。
 * 此程序是HuCart的一部分。  
 * 根据MIT许可证授权(在软件和软件的所有副本中都必须包含版权声明和许可声明。)
 * 官方网址:http://Www.HuCart.Com
 * 技术支持:http://Www.cheermi.com
 * 对于完整的版权和许可证信息，请参阅MIT-LICENSE.TXT
 * 程序的再发布必须保留以上版权声明。
 *
 *@author pgmk<pgmk@hucart.com>
 *@copyright pgmk<pgmk@hucart.com>
 *@link http://www.hucart.com
 *@license The MIT License.
 *----------------------------------------------------------------------------*
**/
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Comment extends HC_Controller
{
	//注意无须构造函数,使用了构造函数得重构父类 parent::__construct();
	function __construct()
	{
		parent::__construct();
		$this->load_lang('user/comment');
		$this -> load('user'); 
		$this -> user -> online_user();
		$this -> load_db();
		
		$this -> load_model('web_config'); 	//加载模型
		$web_config = $this -> web_config_mod -> get_sys_config();
		//$this -> set_view_dir( $web_config['temp'] -> dir );
		$this -> view -> assign('web_config', $web_config);

		$this -> load('helper'); //加载辅助类
		$user_menu = $this -> web_config_mod ->  get_user_menu();
		$get_menu  = $this -> web_config_mod -> get_web_menu();
		$get_link  = $this -> web_config_mod -> get_link();
		$get_user_link = $this -> session->get_user_link( $this->lang['user_link'] );
		
		$this -> view -> assign('user_menu',$user_menu);
		$this -> view -> assign('get_menu',$get_menu);
		$this -> view -> assign('get_link',$get_link);
		$this -> view -> assign('get_user_link',$get_user_link);
	}
 

	
	function buy()
	{
		
		$ckeditorLoad = $this -> helper -> load_ckeditor( 'con_content','','Basic', '#D3D3D3', '580' );	//加载文本编辑器
		$this -> view -> assign('act_url',BASE_WEBURL."/user/index.php?load=comment&act=add_buy");
		
		$this -> view -> assign('ckeditorLoad',$ckeditorLoad);
		
		$this -> view -> display('buy.tpl');
	}
	
	function add_buy()
	{
		$con_titleval 		= $this -> input -> req["con_title"];
		//$use_emailval  		= $this -> input -> req["use_email"];
		$con_contentval  	= $this -> input -> req["con_content"];
		$con_ipval 			= $this -> helper -> get_ip();
		$con_typeval = 1;

		$insert_sql ="INSERT INTO `".$this -> db -> prefix."consult` ( use_id , `con_title` , `con_type`, `con_content` , `con_add_time` , `con_ip` ) VALUES ( ".$_SESSION["user"]["use_id"].", '$con_titleval', '$con_typeval', '$con_contentval', '".time()."', '$con_ipval')"; 
		
		$this -> db -> query_sql( $insert_sql );

		$this -> view -> assign('info_title',$this->lang['add_susse']);
		$this -> view -> assign('URL_TIME',URL_TIME);
		$this -> view -> assign('get_url',BASE_WEBURL."/user/?load=comment&act=buy");
		$this -> view -> display('suggestion.tpl');
		
	
	}
	
	function info_list()
	{

		$use_idval  = $_SESSION["user"]["use_id"];
		$typeval 	= $this -> input -> req["type"] ;
		
		if($typeval =='art')
		{
			$title ='资讯';
			$sqlcom = " SELECT c.* , a.art_id, a.art_title FROM  ".$this -> db -> prefix."comment  as c left join   ".$this -> db -> prefix."article as a on a.art_id = c.com_value_id WHERE  c.com_type = 'art' and   c.use_id = ".$use_idval."  GROUP BY c.com_id ORDER BY c.com_id ";
		}else if($typeval =='pro')
		{
			$title ='商品';
			$sqlcom = " SELECT c.* ,p.pro_id as art_id , p.pro_name as art_title FROM  ".$this -> db -> prefix."comment  as c left join   ".$this -> db -> prefix."product as p on p.pro_id = c.com_value_id WHERE  c.com_type = 'pro' and   c.use_id = ".$use_idval."  GROUP BY c.com_id ORDER BY c.com_id ";
		}else if($typeval =='pic')
		{
			$title ='图片';
			$sqlcom = " SELECT c.* , a.pic_id as art_id , a.pic_title as art_title  FROM  ".$this -> db -> prefix."comment  as c left join   ".$this -> db -> prefix."picture as a on a.pic_id = c.com_value_id WHERE  c.com_type = 'pic' and   c.use_id = ".$use_idval."  GROUP BY c.com_id ORDER BY c.com_id ";
		}else if($typeval =='vid')
		{
			$title ='视频';
			$sqlcom = " SELECT c.* , a.vid_id as art_id , a.vid_title as art_title FROM  ".$this -> db -> prefix."comment  as c left join   ".$this -> db -> prefix."video as a on a.vid_id = c.com_value_id WHERE  c.com_type = 'vid' and   c.use_id = ".$use_idval."  GROUP BY c.com_id ORDER BY c.com_id ";
		}
		$this -> view -> assign('titleval',$title);
		
		$this -> view -> assign('typeval',$typeval);
		$commentInfo = $this -> db -> select_info( $sqlcom );		
		$this -> view -> assign('commentInfo',$commentInfo);
 		$this -> view -> display('comment.tpl');
		

	}
	
 
	function infocom()
	{
		$use_idval 	= $_SESSION["user"]["use_id"] ;
		$typeval 	= $this -> input -> req["type"] ;
		$infoid 	= $GLOBALS['Reque'] -> getval["id"];
		
		if($typeval =='art')
		{
			$title ='资讯';
			$sqlcom = " SELECT c.* , a.art_title FROM  ".$this -> db -> prefix."comment  as c left join  ".$this -> db -> prefix."article as a on a.art_id = c.com_value_id WHERE c.com_id = ".$infoid." and  c.com_type = 'art' and   c.use_id = ".$use_idval."  GROUP BY c.com_id ORDER BY c.com_id  ";
		}else if($typeval =='pro')
		{
			$title ='商品';
			$sqlcom = " SELECT c.* , a.pro_id as art_id , a.pro_name as art_title FROM  ".$this -> db -> prefix."comment  as c left join   ".$this -> db -> prefix."product as a on a.pro_id = c.com_value_id WHERE c.com_id = ".$infoid." and  c.com_type = 'pro' and   c.use_id = ".$use_idval."  GROUP BY c.com_id ORDER BY c.com_id  ";
		}else if($typeval =='pic')
		{
			$title ='图片';
			$sqlcom = " SELECT c.* , a.pic_id as art_id , a.pic_title as art_title  FROM  ".$this -> db -> prefix."comment  as c left join   ".$this -> db -> prefix."picture as a on a.pic_id = c.com_value_id WHERE   c.com_id = ".$infoid." and  c.com_type = 'pic' and   c.use_id = ".$use_idval."  GROUP BY c.com_id ORDER BY c.com_id ";
		}else if($typeval =='vid')
		{
			$title ='视频';
			$sqlcom = " SELECT c.* , a.vid_id as art_id , a.vid_title as art_title FROM  ".$this -> db -> prefix."comment  as c left join   ".$this -> db -> prefix."video as a on a.vid_id = c.com_value_id WHERE   c.com_id = ".$infoid." and c.com_type = 'vid' and   c.use_id = ".$use_idval."  GROUP BY c.com_id ORDER BY c.com_id ";
		}
		
		$commentInfo = $this -> db -> select_one( $sqlcom );

		
		$this -> helper -> load_ckeditor( 'com_content',$commentInfo["com_content"],'Basic',  '#D3D3D3',   '580' );	//加载文本编辑器
		$this -> view -> assign('titleval',$title);
		$this -> view -> assign('typeval',$typeval);
		$this -> view -> assign('commentInfo',$commentInfo); 	
		$this -> view -> assign('act_url',BASE_WEBURL."/user/index.php?load=comment&act=editcom");
		$this -> view -> display('infocomment_tpl.html');
		
	}

	function editcom()
	{
 
		$com_idval 			= $this -> input -> req["com_id"];
		$com_contentval 	= $this -> input -> req["com_content"];	
		$typeval 			= $this -> input -> req["type"] ;

		if( $com_contentval !='' )
		{
			$com_addtimeval = time();
			$updatesql 		= "UPDATE `".$this -> db -> prefix."comment` SET  com_content = '".$com_contentval."'  WHERE  com_id = '".$com_idval."' and use_id = ".$_SESSION["user"]["use_id"] ;
			
			$this -> db -> query_sql( $updatesql );
			$this -> view -> assign('info_title',$this->lang["LA_editsusse"]);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/user/index.php?load=comment&act=info_list&type=".$typeval);
			$this -> view -> display('suggestion.tpl');

		}else{
		
			$this -> view -> assign('info_title',$this->lang["LA_senderror"]);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/user/index.php?load=comment&act=infoart&id=".$com_idval);
			$this -> view -> display('suggestion.tpl');
		
		}
	
			
		
	}
	
	function editpro()
	{
 
		$com_idval 			= $this -> input -> req["com_id"];
		$com_contentval 	= $this -> input -> req["com_content"];	


		if( $com_contentval !='' )
		{
			$com_addtimeval = time();
			$updatesql = "UPDATE `".$this -> db -> prefix."comment` SET  com_content = '".$com_contentval."'  WHERE  com_id = '".$com_idval."' and use_id = ".$_SESSION["user"]["use_id"] ;
			
			$this -> db -> query_sql( $updatesql );
			$this -> view -> assign('info_title',$this->lang["LA_editsusse"]);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/user/index.php?load=comment&act=pro");
			$this -> view -> display('suggestion.tpl');
			
			
		}else{
		
			$this -> view -> assign('info_title',$this->lang["LA_senderror"]);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/user/index.php?load=comment&act=infopro&id=".$com_idval);
			$this -> view -> display('suggestion.tpl');
		
		}
	
			
		
	}
	

	
	function delcom()
	{
		$infoid 	= $GLOBALS['Reque'] -> getval["id"];
		$typeval 	= $this -> input -> req["type"] ;
		$insertcom 	= "  DELETE FROM `".$this -> db -> prefix."comment` WHERE `com_id` in ( $infoid ) and use_id = ".$_SESSION["user"]["use_id"] ;
		$this -> db -> query_sql( $insertcom );
		
		$this -> view -> assign('info_title',$this->lang['bd_delsusse']);
		$this -> view -> assign('URL_TIME',URL_TIME);
		$this -> view -> assign('get_url',BASE_WEBURL."/user/index.php?load=comment&act=info_list&type=".$typeval);
		$this -> view -> display('suggestion.tpl');
	}
	

}

