<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Message
{
	function Message()
	{
		//$GLOBALS['WebSe'] -> isOnLine();

		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/login/actlogin");
	}
	
	function infolist()
	{

		$pageSize = 20 ;
		 
		$pageNumval 	= $GLOBALS['Reque'] -> reqval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}

		if($GLOBALS['Reque'] -> reqval["keyword"] !='')
		{   
			$keywordval 	= $GLOBALS['Reque'] -> reqval["keyword"];
			$keywordval  	= urldecode($keywordval); 
		}
		if($keywordval!='')
		{ 	
			$endArray["keyword"] =$keywordval;
			$endurl 	   .= '&keyword='.urlencode($keywordval);
			$whereadd .= " AND ( f.mes_title LIKE  '%".$keywordval."%' )";  
		}

		$listval  = $GLOBALS['Reque'] -> getval["listval"];
		$listtype = $GLOBALS['Reque'] -> getval["listtype"];

		$orderbyval = "";
		if($listval!='' and $listtype =='DESC' )
		{
			$endArray["listtype"] = 'DESC';
			$endArray["listval"]  = $listval;
			$orderbyval = $listval ."  DESC ";
			$listhtml = '';	//反向排序参数
			
		}elseif($listval!='' )
		{
			$orderbyval = $listval;
			$listhtml = 'DESC';
			
			$endArray["listtype"] = '';
			$endArray["listval"]  = $listval;

		}else{
			$endArray["listtype"] = 'DESC';
			$endArray["listval"]  = 'mes_addtime';
			$orderbyval = " f.mes_addtime DESC , f.`mes_id` DESC ";	
		}


		$sqlQuery = " SELECT f.mes_id,f.tus_id, f.mes_title,f.mes_type,f.mes_status,f.mes_content,f.mes_addtime, u.use_name ,u.use_email ,uf.use_name as ufuse_name FROM ".SQL_PREFIX."message as f left join ".SQL_PREFIX."user as u on f.tus_id = u.use_id left join ".SQL_PREFIX."user as uf on f.fus_id = uf.use_id   WHERE 1   $whereadd  ORDER BY $orderbyval LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."message as f  WHERE 1  $whereadd ORDER BY f.`mes_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);

		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=message&act=infolist' , $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] , $endArray );
		
		$GLOBALS['Templ']->assign('listhtml',$listhtml);
		$GLOBALS['Templ']->assign('listval',$listval);
		$GLOBALS['Templ']->assign('listtype',$listtype);

		$GLOBALS['Templ']->assign('keywordval',$keywordval);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('message_tpl.html');
		
	}
	
	/*
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24

		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=message&act=addinfo");
		$GLOBALS['Templ']->display('adminadd_tpl.html');
	}
	*/
	

	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$insertip 	= "  DELETE FROM `".SQL_PREFIX."message` WHERE `mes_id` in ( $infoid )  ";
		$GLOBALS['MySql'] -> querySql($insertip);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=message&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		//SELECT  f.*,r.mes_content as remes_content  FROM message as fm left join message as rm on r.mes_parentid = f.mes_id  WHERE f.parent_id = 0  and  f.mes_id =
		$sqlQuery = " SELECT f.mes_id,f.tus_id, f.mes_title,f.mes_type,f.mes_status,f.mes_content,f.mes_addtime, u.use_name ,u.use_email ,uf.use_name as ufuse_name FROM ".SQL_PREFIX."message as f left join ".SQL_PREFIX."user as u on f.tus_id = u.use_id left join ".SQL_PREFIX."user as uf on f.fus_id = uf.use_id   WHERE f.mes_id =  ".$infoid;
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'mes_content',$info["mes_content"],'Basic' );	//加载文本编辑器
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=message&act=editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('messageedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$mes_idval 		= $GLOBALS['Reque'] -> funpost("mes_id");
		$mes_titleval 	= $GLOBALS['Reque'] -> funpost("mes_title");
		
		$mes_contentval = trim($_REQUEST["mes_content"]);
		
		
		//$_SESSION["emplyeeUser"]["use_id"] =='' or  $_SESSION["webAdmin"]["admin_name"]
		
		$addsetUp = '';
		
		if($mes_titleval !='' and $mes_contentval !='' )
		{
			$updatedata = "UPDATE `".SQL_PREFIX."message` SET  mes_content = '".$mes_contentval."' , mes_title = '".$mes_titleval."'WHERE   mes_id = ".$mes_idval;
			
			$GLOBALS['MySql'] -> querySql( $updatedata );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=message&act=infolist");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
				
		}else{
		
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=message&act=info&id=".$mes_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24

		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'mes_content','','Basic' );	//加载文本编辑器
		
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=message&act=addinfo");
		$GLOBALS['Templ']->display('messageadd_tpl.html');
		
	}
	
	function addinfo()
	{
		
		$mes_titleval 		= $GLOBALS['Reque'] -> funpost("mes_title");
		$tuse_nameval 		= $GLOBALS['Reque'] -> funpost("tuse_name");
		$mes_contentval 	= trim($_REQUEST["mes_content"]);
 
		
		if( $mes_titleval !='' and $tuse_nameval !='' and $mes_contentval !='' )
		{
			$sqlQuery = " SELECT use_id  FROM  ".SQL_PREFIX."user  WHERE use_name = '".$tuse_nameval."' ORDER BY `use_id` ";
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["use_id"] > 0 )
			{
				$fus_idval = $_SESSION["emplyeeUser"]["use_id"];
				$tus_idval = $info["use_id"];
				$mes_addtimeval 	= time();
				
				$insertsql =" INSERT INTO `".SQL_PREFIX."message` (`mes_title` , `mes_content` , `mes_type` ,`tus_id` ,`fus_id` , `mes_addtime` ) VALUES (  '$mes_titleval',  '$mes_contentval', '$mes_typeval','$tus_idval','$fus_idval', '$mes_addtimeval')";
				
				$GLOBALS['MySql'] -> querySql($insertsql);
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=message&act=infolist");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}else{
				
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_nousererror']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=message&act=add");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}
			
		}else{
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=message&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
		
}

//nmon_x86_rhel4


$Message = new Message();

?>