<?php
/**
 *----------------------------------------------------------------------------*
 * 版权所有 2005-2013 GV32.COM，并保留所有权利。
 * 网站地址: http://www.gv32.com；
 * 作者: GV32.COM
 *----------------------------------------------------------------------------*
**/

class Message
{
	function Message()
	{
		$GLOBALS['Helpe']-> get_usermenu();
		
		$getmenu = $GLOBALS['Helpe']->get_menu();
		$GLOBALS['Templ']->assign('getmenu',$getmenu);
		
		$getlink = $GLOBALS['Helpe']->get_link();
		$GLOBALS['Templ']->assign('getlink',$getlink);
		
		$getuserlink = $GLOBALS['WebSe']->getuserlink();
		$GLOBALS['Templ']->assign('getuserlink',$getuserlink);
		
		//$userdetail = $this -> userdetail();
		
	}
	
	function sendinfo()
	{
		$this -> userMessage();
		
		$webtitle = '发件箱 - 用户中心';
		
		//处理你现在的位置
		$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 发件箱';
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);

		//$GLOBALS['Templ'] -> assign('actUrl',BASE_WEBURL."/user/index.php?load=user&act=updateuser");
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'mes_content','','Basic',$uiColor = '#D3D3D3', $width = '580' );	//加载文本编辑器
		
		$GLOBALS['Templ'] -> assign('actUrl',BASE_WEBURL."/user/?load=message&act=addmessage");
		
		$GLOBALS['Templ']-> display('message_tpl.html');
	}
	
	function addmessage()
	{
		$fus_idval 				= $_SESSION["webUser"]["use_id"];
		$mes_titleval 			= $GLOBALS['Reque'] -> funpost("mes_title");
		$mes_contentval 		= $GLOBALS['Reque'] -> funpost("mes_content");	
		$use_nameval 			= $GLOBALS['Reque'] -> funpost("use_name");
		
		$sqlQuery = " SELECT use_id,use_email  FROM  ".SQL_PREFIX."user  WHERE use_name = '".$use_nameval."' ORDER BY `use_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		if($info["use_id"] > 0 )
		{
			$tus_idval = $info["use_id"];
			$use_emailval = $info["use_email"];
			$mes_addtimeval = time();
			$insertsql = "INSERT INTO `".SQL_PREFIX."message` (  `tus_id`,`fus_id`, `mes_title` , `mes_content` , `mes_addtime` , `use_email` )
VALUES ( $tus_idval , '$fus_idval', '$mes_titleval', '$mes_contentval', '$mes_addtimeval', '$use_emailval' )";
		
			$GLOBALS['MySql'] -> querySql( $insertsql );
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']["LA_addsend"]);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=message&act=sendinfo");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}else{
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']["LA_senderror"]);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=message&act=sendinfo");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	
	}

	function replayeditinfo()
	{
		$fus_idval 				= $_SESSION["webUser"]["use_id"];
		$mes_parentidval 		= $GLOBALS['Reque'] -> funpost("mes_id");
		$mes_titleval 			= $GLOBALS['Reque'] -> funpost("mes_title");
		$mes_contentval 		= $GLOBALS['Reque'] -> funpost("mes_content");	
		$use_nameval 			= $GLOBALS['Reque'] -> funpost("use_name");
		
		$tus_idval 			= $GLOBALS['Reque'] -> funpost("tus_id");
		
		$sqlQuery = " SELECT use_id,use_email  FROM  ".SQL_PREFIX."user  WHERE use_name = '".$use_nameval."' ORDER BY `use_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		if($info["use_id"] > 0 )
		{
			$tus_idval = $info["use_id"];
			$use_emailval = $info["use_email"];
			$mes_addtimeval = time();
			$insertsql = "INSERT INTO `".SQL_PREFIX."message` (  `tus_id`,`mes_parentid`,`fus_id`, `mes_title` , `mes_content` , `mes_addtime` , `use_email` )
VALUES ( $tus_idval , '$mes_parentidval','$fus_idval', '$mes_titleval', '$mes_contentval', '$mes_addtimeval', '$use_emailval' )";
		
			$GLOBALS['MySql'] -> querySql( $insertsql );
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']["LA_addsend"]);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=message&act=sendinfo");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			
		}else{
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']["LA_senderror"]);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=message&act=sendinfo");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	
	}

	function userMessage()
	{
		$fus_idval = $_SESSION["webUser"]["use_id"] ;
		
		$sqladdress = " SELECT m.*, u.use_name  FROM  ".SQL_PREFIX."message as m ,".SQL_PREFIX."user as u   WHERE m.tus_id = u.use_id and  m.fus_id = ".$fus_idval."  GROUP BY m.mes_id ORDER BY m.`mes_id` LIMIT 0 , 1000";
		
		$AddressInfo = $GLOBALS['MySql'] -> selectInfo( $sqladdress );
				
		$GLOBALS['Templ'] -> assign('AddressInfo',$AddressInfo);

	}
	
	function info(  )
	{
		$webtitle = '站内信息 - 用户中心';
		//处理你现在的位置
		$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 站内信息';
		
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
		
		
		$infoid = $GLOBALS['Reque'] -> getval["id"];

		$sqlQuery = " SELECT m.* ,u.use_name FROM ".SQL_PREFIX."message as m , ".SQL_PREFIX."user as u  WHERE m.tus_id = u.use_id and  m.mes_id =  ".$infoid." and m.fus_id = ".$_SESSION["webUser"]["use_id"] ;
		
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'mes_content',$info["mes_content"],'Basic',$uiColor = '#D3D3D3', $width = '580' );	//加载文本编辑器
		
		$GLOBALS['Templ']->assign('actUrl',BASE_WEBURL."/user/index.php?load=message&act=editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('messageedit_tpl.html');
	
	}
	
	function readinfo(  )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		//读取信息
		$mes_readtimeval = time();
		$updatesql = "UPDATE `".SQL_PREFIX."message` SET  mes_isread = '1' ,  mes_readtime = '".$mes_readtimeval."' WHERE  mes_id = ".$infoid." and tus_id = ".$_SESSION["webUser"]["use_id"] ;
			
		$GLOBALS['MySql'] -> querySql( $updatesql );
		
		
		

		$sqlQuery = " SELECT m.* ,u.use_name FROM ".SQL_PREFIX."message as m , ".SQL_PREFIX."user as u  WHERE m.tus_id = u.use_id and  m.mes_id =  ".$infoid." and m.tus_id = ".$_SESSION["webUser"]["use_id"] ;
		
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'mes_content','','Basic',$uiColor = '#D3D3D3', $width = '580' );	//加载文本编辑器
		
		$GLOBALS['Templ']->assign('actUrl',BASE_WEBURL."/user/index.php?load=message&act=replayeditinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('messageread_tpl.html');
	
	}
	
	function receiveinfo()
	{
		$tus_idval = $_SESSION["webUser"]["use_id"] ;
		
		$sqladdress = " SELECT m.*, u.use_name  FROM  ".SQL_PREFIX."message as m ,".SQL_PREFIX."user as u   WHERE m.fus_id = u.use_id and  m.tus_id = ".$tus_idval."  GROUP BY m.mes_id ORDER BY m.`mes_id` LIMIT 0 , 1000";
		
		$receiveInfo = $GLOBALS['MySql'] -> selectInfo( $sqladdress );
				
		$GLOBALS['Templ'] -> assign('receiveInfo',$receiveInfo);
		
		$GLOBALS['Templ']->assign('actUrl',BASE_WEBURL."/user/index.php?load=message&act=editinfo");
		
		$GLOBALS['Templ'] -> assign('info',$info);
		
		$webtitle = '收件箱 - 用户中心';
		//处理你现在的位置
		$nowaddress = '您现在所在的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 收件箱';
		
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
		
		$GLOBALS['Templ'] -> display('messagereplay_tpl.html');
		
	}
	
	
	function editinfo()
	{
		
		$mes_idval 				= $GLOBALS['Reque'] -> funpost("mes_id");

		$fus_idval 				= $_SESSION["webUser"]["use_id"];
		$mes_titleval 			= $GLOBALS['Reque'] -> funpost("mes_title");
		$mes_contentval 		= $GLOBALS['Reque'] -> funpost("mes_content");	
		$use_nameval 			= $GLOBALS['Reque'] -> funpost("use_name");
		
		$sqlQuery = " SELECT use_id,use_email  FROM  ".SQL_PREFIX."user  WHERE use_name = '".$use_nameval."' ORDER BY `use_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);


		if($info["use_id"] > 0 )
		{
			$tus_idval = $info["use_id"];
			$use_emailval = $info["use_email"];
			$mes_addtimeval = time();
			$updatesql = "UPDATE `".SQL_PREFIX."message` SET  tus_id = '".$tus_idval."' ,  mes_title = '".$mes_titleval."' , mes_content = '".$mes_contentval."' , use_email = '".$use_email."' , mes_addtime = '".$mes_addtime."'  WHERE  mes_id = '".$mes_idval."'  and fus_id =  '".$fus_idval."'";
			
			$GLOBALS['MySql'] -> querySql( $updatesql );
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']["LA_editsusse"]);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=message&act=sendinfo");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
			
			
		}else{
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']["LA_senderror"]);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=message&act=sendinfo");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
		
		}
	
			
		
	}
	
	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$insertip 	= "  DELETE FROM `".SQL_PREFIX."message` WHERE `mes_id` in ( $infoid ) and fus_id = ".$_SESSION["webUser"]["use_id"] ;
		$GLOBALS['MySql'] -> querySql($insertip);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=message&act=sendinfo");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function shortinfo()
	{
		$tus_idval = $_SESSION["webUser"]["use_id"] ;
		
		$sqlshort = " SELECT * FROM  ".SQL_PREFIX."shortinfo as s   WHERE   tus_id = ".$tus_idval."  GROUP BY sho_id ORDER BY `sho_id` LIMIT 0 , 100";
		
		$shortInfo = $GLOBALS['MySql'] -> selectInfo( $sqlshort );
			
		$webtitle = '短信提醒 - 用户中心';
		//处理你现在的位置
		$nowaddress = '您现在所在的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 短信提醒';
		
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
				
		$GLOBALS['Templ'] -> assign('shortInfo',$shortInfo);	
		$GLOBALS['Templ'] -> display('shortinfo_tpl.html');
		
	}
	
	function delshort( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$insertip 	= "  DELETE FROM `".SQL_PREFIX."shortinfo` WHERE `sho_id` in ( $infoid ) and tus_id = ".$_SESSION["webUser"]["use_id"] ;
		$GLOBALS['MySql'] -> querySql($insertip);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',BASE_WEBURL."/user/index.php?load=message&act=shortinfo");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function readshortinfo(  )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		//读取信息
		$sho_readtimeval = time();
		$updatesql = "UPDATE `".SQL_PREFIX."shortinfo` SET  sho_isread = '1' ,  sho_readtime = '".$sho_readtimeval."' WHERE sho_id = ".$infoid." and tus_id = ".$_SESSION["webUser"]["use_id"] ;
		$GLOBALS['MySql'] -> querySql( $updatesql );

		$sqlQuery = " SELECT * FROM ".SQL_PREFIX."shortinfo   WHERE  sho_id =  ".$infoid." and tus_id = ".$_SESSION["webUser"]["use_id"] ;
		
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);

		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('shortinforead_tpl.html');
	
	}
	
	function book()
	{
		//现推荐8个最新商品
		
		$sqlQuery 	= " SELECT pro_id, pro_name ,pro_img, pro_uptime   FROM  ".SQL_PREFIX."product   WHERE pro_enabled = 1 $addsql  GROUP BY  pro_id ORDER BY pro_uptime DESC , `pro_id` LIMIT  0 , 8 ";
		$info 		= $GLOBALS['MySql']  ->  selectInfo( $sqlQuery );
		//var_dump($info);
		$GLOBALS['Templ'] -> assign('info',$info);
		
		$webtitle = '我的订阅 - 用户中心';
		//处理你现在的位置
		$nowaddress = '您现在所在的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/user/">用户中心</a> > 我的订阅';
		
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
		
		$GLOBALS['Templ'] -> display('booklist_tpl.html');
			
	}
}

$Message = new Message();
?>