<?php
/***
 *----------------------------------------------------------------------------*
 * 版权所有 2010-2016 HuCart.COM，并保留所有权利。
 * 此程序是HuCart的一部分。  
 * 根据MIT许可证授权(在软件和软件的所有副本中都必须包含版权声明和许可声明。)
 * 官方网址:http://www.hucart.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
{
	
	function __construct()
	{
		parent::__construct();
		$this -> load_db();
		$this -> load_lang('www/article');
		$this -> load('helper');     	 	//加载辅助类
		$this -> load_model('ads'); 		//加载模型
		$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 -> view -> assign('menu_info',$this -> web_config_mod -> get_web_menu());
		$this -> view -> assign('ads_info', $this -> ads_mod -> get_ads( '1,2,3,4,5,6,7,8,9,10,11'  ));
		$this -> view -> assign('user_link',$this -> session -> get_user_link( $this->lang['user_link'] ));
		

		$this -> load_model('personal'); //加载模型
		$art_sort = $this -> personal_mod  -> get_sort('art_sort');
		$this -> view -> assign('art_sort',$art_sort);
		
		$contact_arr =  $this -> helper -> build_contact( $web_config );
		$this -> view -> assign('contact_arr',$contact_arr);
		
		//var_dump($web_info);
		//var_dump($GLOBALS);
	}
	
	function Comment()
	{

		$getmenu = $this -> helper -> get_menu();
		$this -> view -> assign('getmenu',$getmenu);

	
		$getlink = $this -> helper -> get_link();
		$this -> view -> assign('getlink',$getlink);	
		
		$getads = $this -> helper -> get_ads( $instr = '1,2,3,4,5,6,7,8,9,10,11' );
		$this -> view -> assign('getads',$getads);
		
		$getuserlink = $GLOBALS['WebSe']->getuserlink();
		$this -> view ->assign('getuserlink',$getuserlink);
 
	}
	
	function info_list()
	{
		$webtitle = '全部评议';
		//处理你现在的位置
		$now_address = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/index.php?/comment.html">全部评议</a>';

		
		$id 		= $this -> input -> get["id"];
		$page_num 	= $this -> input -> get["page"];
		$keyword    = $this -> input -> req["keyword"];
		
		if($sid != '' and $keyword !='')
		{
			$addsql = " AND com_value_id = ".$sid." AND com_type = '".$keyword."' " ; 
			//$endArray["sid"] = $sid;
			//$endArray["keyword"] = $keyword;
		}
		
		$page_size = 20 ;
		
		if( $page_num > 1 )
		{
			$page_num  = $page_num;
			$limit_num = ceil( ( $page_num -1 ) * $page_size );
		}else{
			$page_num  = 1;
			$limit_num = 0 ;
		}
		
		$sql_query = " SELECT com_id, com_type , com_value_id ,com_content, com_add_time,com_ip  FROM  ".$this -> db -> prefix."comment   WHERE  com_enabled = 1  $addsql  GROUP BY  com_id ORDER BY  com_add_time DESC ,`com_id` DESC  LIMIT  $limit_num , $page_size ";
		$info 		= $this -> db ->  select_info( $sql_query );
		//var_dump($info);

 
		$sql_query 	= " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."comment  WHERE  com_enabled = 1 $addsql ORDER BY `com_id`  ";
		$infocount 	= $this -> db ->  select_one( $sql_query );


		$url = BASE_WEBURL.'/index.php?/comment-info_list-'.$sid.'.html';
 		$this -> load('page',$this->lang['page']);
		$page_str = $this -> page -> buildpage_str( $url , $page_num  , $page_size  , $result_count = $infocount["CNUM"] ,$endArray);
		
		
 
		$this -> view -> assign('info',$info);
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('webtitle',$webtitle);
		$this -> view -> assign('now_address',$now_address);
		
		$this -> view -> display('comment.tpl');
	}
	
	function add_info()
	{
		$com_typeval 		= $this -> input -> req["com_type"];
		$com_value_idval  	= $this -> input -> req["com_value_id"];
		$com_contentval  	= $GLOBALS['Reque'] -> delContent($_REQUEST["com_content"]);
		
		//查询是否登录，没有登录，先登录后再提交
		if($_SESSION["webUser"]["use_id"] =='' or  $_SESSION["webUser"]["use_name"] =='' )
		{
			header("location:".BASE_WEBURL."/user/login.php?load=login&act=act&backurl=".urlencode(BASE_WEBURL."/?".$com_typeval."-".$com_value_idval.".html"));
			exit();

		}else if($com_contentval == '')
		{
			$this -> view -> assign('info_title',$_LANG['bd_addempty']);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/?load=".$com_typeval."&act=detail&id=".$com_value_idval);
			$this -> view -> display('suggestion.tpl');
		}else{
		
			//已经登录
			$use_idval 			= $_SESSION["webUser"]["use_id"];
			$com_nicknameval 	= $_SESSION["webUser"]["use_name"];
			$com_add_timeval 	= time();	
			$com_ipval 			= $this -> helper -> get_ip();
	
			$insertsql ="INSERT INTO `".$this -> db -> prefix."comment` (`use_id`,`com_nickname`,`com_type` , `com_value_id` , `com_content` , `com_add_time` , `com_ip` ) VALUES ( '$use_idval','$com_nicknameval', '$com_typeval', '$com_value_idval', '$com_contentval', '$com_add_timeval', '$com_ipval')"; 
			
			$this -> db -> query_sql($insertsql);
			
			$this -> view -> assign('info_title',$_LANG['bd_addsusse']);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/?".$com_typeval."-".$com_value_idval.".html");
			$this -> view -> display('suggestion.tpl');
		}
		
	
	}
	
	function addbook()
	{
		$fav_typeval 		= $this -> input -> req["fav_type"];
		$fav_idvalueval  	= $this -> input -> req["fav_id"];
		$fav_titleval  		= $GLOBALS['Reque'] -> delContent($_REQUEST["fav_title"]);
		
		//查询是否登录，没有登录，先登录后再提交
		if($_SESSION["webUser"]["use_id"] =='' or  $_SESSION["webUser"]["use_name"] =='' )
		{
			header("location:".BASE_WEBURL."/user/login.php?load=login&act=act&backurl=".urlencode(BASE_WEBURL."/?".$fav_typeval."-".$fav_idvalueval.".html"));
			exit();

		}else if($fav_titleval == '')
		{
			$this -> view -> assign('info_title',$_LANG['bd_addempty']);
			$this -> view -> assign('URL_TIME',URL_TIME);
			$this -> view -> assign('get_url',BASE_WEBURL."/?load=".$fav_typeval."&act=detail&id=".$fav_idvalueval);
			$this -> view -> display('suggestion.tpl');
		}else{
			
			//查询是否已经添加过
			$sqlfav 	= " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."favorite  WHERE  fav_type = '".$fav_typeval."'  and fav_idvalue = '".$fav_idvalueval."'  ORDER BY `fav_id`  ";
			$infofav 	= $this -> db ->  select_one( $sqlfav );
			
			if($infofav["CNUM"] > 0  )
			{
				$this -> view -> assign('info_title',$_LANG['bd_addold']);
				$this -> view -> assign('URL_TIME',URL_TIME);
				$this -> view -> assign('get_url',BASE_WEBURL."/?".$fav_typeval."-".$fav_idvalueval.".html");
				$this -> view -> display('suggestion.tpl');
				
			}else{
			
			
				//已经登录
				$use_idval 			= $_SESSION["webUser"]["use_id"];
				$fav_nicknameval 	= $_SESSION["webUser"]["use_name"];
				$fav_addtimeval 	= time();	
				$fav_ipval 			= $this -> helper -> get_ip();
		
				$insertsql ="INSERT INTO `".$this -> db -> prefix."favorite` (`use_id`,`fav_nickname`,`fav_type` , `fav_idvalue` , `fav_title` , `fav_addtime` , `fav_ip` ) VALUES ( '$use_idval','$fav_nicknameval', '$fav_typeval', '$fav_idvalueval', '$fav_titleval', '$fav_addtimeval', '$fav_ipval')"; 
				
				$this -> db -> query_sql($insertsql);
				
				$this -> view -> assign('info_title',$_LANG['bd_favsusse']);
				$this -> view -> assign('URL_TIME',URL_TIME);
				$this -> view -> assign('get_url',BASE_WEBURL."/?".$fav_typeval."-".$fav_idvalueval.".html");
				$this -> view -> display('suggestion.tpl');
			}
		}
		
	
	}
		
}

