<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Forum
{
	function Forum()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/login/actlogin");
		
	}
	
	function info_list(  )
	{
		$page_size = 20 ;		
		$page_num_val 	= $this -> input ->  req["page_num"];
		
		if( $page_num_val > 1 )
		{
			$page_num  = $page_num_val;
			$limit_num = ceil( ( $page_num_val -1 ) * $page_size );
		}else{
			$page_num  = 1;
			$limit_num = 0 ;
		}
			
		$sql_query = " SELECT for_id, for_name, for_desc, for_image, for_list,for_enabled FROM  ".$this -> db -> prefix."forum  WHERE 1 GROUP BY for_id ORDER BY `for_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as LNUM  FROM  ".$this -> db -> prefix."forum  WHERE 1  ORDER BY `for_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		//var_dump();
		$page_str = $this -> page ->get_admin_page( $url = '?load=forum&act=info_list', $page_num  , $page_size  , $result_count = $infocount["LNUM"]);
		
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('forum.tpl');
		
	}
	
	function add(  )
	{
		///$this -> view ->  caching = true;
		//$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24
 
		$this -> view -> display('forumadd.tpl');
	}
	
	function add_info()
	{
		$for_nameval 	= $this -> input ->  funpost("for_name");
		$for_descval 	= $this -> input ->  funpost("for_desc");
		$for_imageval 	= $this -> input ->  funpost("for_image");
		$for_listval 	= $this -> input ->  funpost("for_list");
		$for_enabledval = $this -> input ->  funpost("for_enabled");
		
		if($for_nameval and $for_descval)
		{
			$sql_query = " SELECT count(1) as LNUM  FROM  ".$this -> db -> prefix."forum  WHERE for_name = '".$for_nameval."' ORDER BY `for_id` ";
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["LNUM"] < 1 )
			{
				$insertip =" INSERT INTO `".$this -> db -> prefix."forum` (`for_name` , `for_desc` , `for_image` , `for_list` , `for_enabled` ) VALUES (  '$for_nameval', '$for_descval', '$for_imageval', '$for_listval', '$for_enabledval')";
				
				$this -> db -> query_sql($insertip);
				
				$this -> view ->  assign('info_title',$this->lang['add_success']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=forum&act=info_list");
				$this -> view ->  display('suggestion.tpl');	
			}else{
				
				$this -> view ->  assign('info_title',$this->lang['err_info_exist']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=forum&act=add");
				$this -> view ->  display('suggestion.tpl');	
			}
			
		}else{
			
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=forum&act=add");
			$this -> view ->  display('suggestion.tpl');		}
		//var_dump($_REQUEST);
	}
	
	function del()
	{
		$indel = implode(',', $delArray);
		$insertip = " DELETE FROM `".$this -> db -> prefix."forum` WHERE `forum`.`for_id` in ( $indel ) ";
		$this -> db -> query_sql($insertip);
		$this -> view ->  assign('info_title',$this->lang['del_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=forum&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $this -> input ->  req["id"];
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."forum  WHERE for_id = '".$infoid."' ORDER BY `for_id` ";
		$info = $this -> db -> select_one($sql_query);
		//var_dump($info);
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('forumedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$for_idval 	= $this -> input ->  funpost("for_id");
		$for_nameval 	= $this -> input ->  funpost("for_name");
		$for_descval 	= $this -> input ->  funpost("for_desc");
		$for_imageval 	= $this -> input ->  funpost("for_image");
		$for_listval 	= $this -> input ->  funpost("for_list");
		$for_enabledval = $this -> input ->  funpost("for_enabled");
		
		if($for_nameval !='' and $for_descval !='' and $for_idval !='')
		{
			$updateforum = "UPDATE `".$this -> db -> 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."' ";
			
			$this -> db -> query_sql( $updateforum );
			
			$this -> view ->  assign('info_title',$this->lang['edit_success']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=forum&act=info_list");
			$this -> view ->  display('suggestion.tpl');
				
		}else{
		
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=forum&act=info&id=".$for_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
		
}

//


$Forum = new Forum();

?>