<?php
class Reply
{
	//var $nowaddress = '';
	function Reply()
	{
		$getmenu = $GLOBALS['Helpe']->get_menu();
		$GLOBALS['Templ']->assign('getmenu',$getmenu);
		
		$getbbsconfig = $GLOBALS['Helpe']->get_bbsconfig();
		$GLOBALS['Templ']-> assign('getbbsconfig',$getbbsconfig);
		
		$getlink = $GLOBALS['Helpe']->get_link();
		$GLOBALS['Templ']->assign('getlink',$getlink);

		$getuserlink = $GLOBALS['WebSe']->getuserlink();
		$GLOBALS['Templ']->assign('getuserlink',$getuserlink);

		$getads = $GLOBALS['Helpe'] -> get_ads( $instr = '1,2,3,4,5,6,7,8,9,10,11' );
		$GLOBALS['Templ'] -> assign('getads',$getads);
		
		$this -> nowaddress = '<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/bbs/">'.$getbbsconfig["bbsname"].'</a>';
		
	}

	
	function infolist()
	{
		//公司简介
		$idval 		 = $GLOBALS['Reque'] -> reqval["id"];
		$pageNumval  = $GLOBALS['Reque'] -> reqval["pageNum"];
		$pageSize = 20 ;
		
		//var_dump($strArray );
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}
 
 
		$sqlQuery = " SELECT r.rep_id, r.rep_desc ,r.rep_addtime, r.rep_list,d.usd_nick FROM ".SQL_PREFIX."reply AS r , ".SQL_PREFIX."userdetail as d    WHERE d.use_id = r.use_id and  r.rep_enabled = 1  and r.thr_id = ".$idval." GROUP BY r.rep_id ORDER BY  r.rep_addtime DESC ,  r.rep_list , r.rep_id desc  LIMIT  $LIMITnum , $pageSize ";
		
		$info 		= $GLOBALS['MySql']  ->  selectInfo($sqlQuery);
		
		
		$sqlQuery 	= " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."reply  WHERE rep_enabled = 1 and thr_id = ".$idval."  ORDER BY `rep_id`  ";
		
		
		$infocount 	= $GLOBALS['MySql']  ->  selectOne($sqlQuery);
		
		$PageStr = $GLOBALS['Page'] -> buildPageStr( $url = '/bbs/index.php/thread/infolist/'.$idval, $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] );
		
		$GLOBALS['Templ'] -> assign('PageStr',$PageStr );
		
		
		$GLOBALS['Templ'] -> assign('info', $info );


		$sqlinfo = " SELECT thr_id, thr_title,thr_desc,thr_addtime, thr_list  FROM  ".SQL_PREFIX."thread  WHERE thr_enabled = 1 and thr_id = ".$idval."  ";
		
		$threadInfo = $GLOBALS['MySql'] -> selectOne($sqlinfo);
		
		$upthread = "UPDATE   ".SQL_PREFIX."thread  SET thr_count = thr_count + 1 WHERE  thr_enabled = 1 and thr_id = ".$idval." ";
		
		$GLOBALS['MySql'] -> querySql( $upthread );
		
		$this -> nowaddress .= ' > <a href="'.BASE_WEBURL.'/bbs/index.php/thread/infolist/'.$threadInfo["thr_id"].'/1">'.$threadInfo["thr_title"].'</a>';
		
		$GLOBALS['Templ']->assign('nowaddress', $this -> nowaddress );
		
		//$comInfo = array();
		$GLOBALS['Templ']->assign('threadInfo', $threadInfo);
		
		$GLOBALS['Templ']-> display('thread_tpl.html');
		
		
	}
	
	function add()
	{
		$idval 	= $GLOBALS['Reque'] -> reqval["id"];
		
		$GLOBALS['WebSe'] -> isLoginUser( $getUrl = BASE_WEBURL.'/bbs/index.php?load=reply&act=add&id='.$idval );
		
		
		$sqlQuery = " SELECT  * FROM  ".SQL_PREFIX."thread  WHERE thr_id = ".$idval." GROUP BY thr_id ORDER BY thr_id desc  ";
		
		$info 	  = $GLOBALS['MySql']  ->  selectOne($sqlQuery);

		$this -> nowaddress .= ' > <a href="'.BASE_WEBURL.'/bbs/index.php?load=forum&act=infolist&id='.$idval.'">'.$info["for_name"].'</a>';
		
		$GLOBALS['Templ'] -> assign('nowaddress',$this -> nowaddress);

		$GLOBALS['Templ'] -> assign('info',$info);
		
		$GLOBALS['Templ'] -> assign('idval',$idval);
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'rep_desc','','Basic','','510' );	//加载文本编辑器
		
		$GLOBALS['Templ'] -> display('replyadd_tpl.html');
		
	}
	
	function addinfo()
	{
		
		$rep_descval 	= $_REQUEST["rep_desc"];
		
		///echo $iiii 	= $GLOBALS['Reque'] -> reqval["iiii"];
		
		$thr_idval 		= $GLOBALS['Reque'] -> funpost("thr_id");
		$rep_uptimeval 	= $rep_addtimeval = time();
		
		$rep_ipval 		= $GLOBALS['Helpe'] -> getip();
		$use_idval 		= $_SESSION["webUser"]["use_id"];
		
		$rep_enabledval = 1;
		
		$insertsql ="INSERT INTO `".SQL_PREFIX."reply` ( `rep_desc` , `rep_addtime` ,`rep_uptime` , `use_id`, `rep_ip`,`thr_id` ,`rep_enabled`) VALUES (   '$rep_descval', '$rep_addtimeval', '$rep_uptimeval', '$use_idval','$rep_ipval','$thr_idval','$rep_enabledval')"; 
		
		$GLOBALS['MySql'] -> querySql( $insertsql );
		
		$upthread = "UPDATE   ".SQL_PREFIX."thread  SET thr_replycount = thr_replycount + 1 WHERE  thr_enabled = 1 and thr_id = ".$thr_idval." ";
		
		$GLOBALS['MySql'] -> querySql( $upthread );
		
		///bbs/index.php?load=forum&act=infolist&id=1
		
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL.'/bbs/index.php?load=thread&act=infolist&id='.$thr_idval);
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
}


$Reply = new Reply();
?>