<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Forum
{
	function Forum()
	{
		//$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 ;
		}
			
		$sqlQuery = " SELECT for_id, for_name, for_desc, for_image, for_list,for_enabled FROM  ".SQL_PREFIX."forum  WHERE 1 GROUP BY for_id ORDER BY `for_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."forum  WHERE 1  ORDER BY `for_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump();
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=forum&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["LNUM"]);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('forum_tpl.html');
		
	}
	
	function add(  )
	{
		///$GLOBALS['Templ'] -> caching = true;
		//$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
 
		$GLOBALS['Templ']->display('forumadd_tpl.html');
	}
	
	function addinfo()
	{
		$for_nameval 	= $GLOBALS['Reque'] -> funpost("for_name");
		$for_descval 	= $GLOBALS['Reque'] -> funpost("for_desc");
		$for_imageval 	= $GLOBALS['Reque'] -> funpost("for_image");
		$for_listval 	= $GLOBALS['Reque'] -> funpost("for_list");
		$for_enabledval = $GLOBALS['Reque'] -> funpost("for_enabled");
		
		if($for_nameval and $for_descval)
		{
			$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."forum  WHERE for_name = '".$for_nameval."' ORDER BY `for_id` ";
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["LNUM"] < 1 )
			{
				$insertip =" INSERT INTO `".SQL_PREFIX."forum` (`for_name` , `for_desc` , `for_image` , `for_list` , `for_enabled` ) VALUES (  '$for_nameval', '$for_descval', '$for_imageval', '$for_listval', '$for_enabledval')";
				
				$GLOBALS['MySql'] -> querySql($insertip);
				
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=forum&act=infolist");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}else{
				
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_isrealyerror']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=forum&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=forum&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
		//var_dump($_REQUEST);
	}
	
	function del()
	{
		$indel = implode(',', $delArray);
		$insertip = " DELETE FROM `".SQL_PREFIX."forum` WHERE `forum`.`for_id` in ( $indel ) ";
		$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=forum&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $GLOBALS['Reque'] -> reqval["id"];
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."forum  WHERE for_id = '".$infoid."' ORDER BY `for_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump($info);
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('forumedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$for_idval 	= $GLOBALS['Reque'] -> funpost("for_id");
		$for_nameval 	= $GLOBALS['Reque'] -> funpost("for_name");
		$for_descval 	= $GLOBALS['Reque'] -> funpost("for_desc");
		$for_imageval 	= $GLOBALS['Reque'] -> funpost("for_image");
		$for_listval 	= $GLOBALS['Reque'] -> funpost("for_list");
		$for_enabledval = $GLOBALS['Reque'] -> funpost("for_enabled");
		
		if($for_nameval !='' and $for_descval !='' and $for_idval !='')
		{
			$updateforum = "UPDATE `".SQL_PREFIX."forum` SET  for_name = '".$for_nameval."' , for_desc = '".$for_descval."' , for_image = '".$for_imageval."', for_list = '".$for_listval."',for_enabled = '".$for_enabledval."'  WHERE  for_id = '".$for_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updateforum );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=forum&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=forum&act=info&id=".$for_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
		
}

//nmon_x86_rhel4


$Forum = new Forum();

?>