<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Leaveword
{
	function Leaveword()
	{
		//$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 fm.lwd_id,fm.user_id,fm.user_name,fm.lwd_title,fm.lwd_type,fm.lwd_status,fm.lwd_content,fm.lwd_time,rm.lwd_id as rmlwd_id,rm.lwd_content as rmlwd_content,rm.admin_name as rmuser_name FROM leaveword as fm left join leaveword as rm on rm.lwd_parentid = fm.lwd_id  WHERE fm.lwd_parentid = 0  LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  leaveword  WHERE lwd_parentid = 0  ORDER BY `lwd_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		//var_dump($info);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=leaveword&act=info_list', $page_num  , $page_size  , $result_count = $infocount["CNUM"] );
		
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('leaveword.tpl');
		
	}
	
 
	

	function del( )
	{
		$indel 		= implode(',', $delArray);
		$insertip 	= "  DELETE FROM `msg` WHERE `msg`.`lwd_id` in ( $indel ) or `msg`.`lwd_parentid`  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?/msg/info_list/");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid   = $infoArray[0];
		//SELECT  fm.*,rm.lwd_content as relwd_content  FROM msg as fm left join msg as rm on rm.lwd_parentid = fm.lwd_id  WHERE fm.parent_id = 0  and  fm.lwd_id =
		$sql_query = " SELECT  fm.*, rm.lwd_content as relwd_content,rm.lwd_id as rmlwd_id  FROM msg as fm left join msg as rm on rm.lwd_parentid = fm.lwd_id  WHERE fm.lwd_parentid = 0  and  fm.lwd_id ='".$infoid."' ORDER BY fm.`lwd_id` ";
		$info = $this -> db -> select_one($sql_query);
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/msg/edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('leavewordedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$lwd_parentidval 	= $this -> input ->  funpost("lwd_parentid");
		$relwd_contentval 	= $this -> input ->  funpost("relwd_content");
		
		$rmlwd_idval 	= $this -> input ->  funpost("rmlwd_id");
		
		$replylwd_titleval 	= "reply:".$this -> input ->  funpost("lwd_title");
		
		$lwd_timeval = time();
		
		//$_SESSION["emplyeeUser"]["use_id"] =='' or  $_SESSION["webAdmin"]["admin_name"]
		
		$addsetUp = '';
		
		if($lwd_parentidval !='' and $relwd_contentval !='' )
		{
			///"UPDATE `links` SET  link_name = '".$link_nameval."' , link_url = '".$link_urlval."' , link_logo = '".$link_logoval."', link_list = '".$link_listval."',link_istrue = '".$link_istrueval."'  WHERE  link_id = '".$link_idval."' ";
			
			if($rmlwd_idval!='')
			{
				$updatedata = "UPDATE `msg` SET  lwd_content = '".$relwd_contentval."' , admin_id = '".$_SESSION["emplyeeUser"]["use_id"]."' , admin_name = '".$_SESSION["webAdmin"]["admin_name"]."' ,`lwd_time`= '$lwd_timeval' WHERE   lwd_id = ".$rmlwd_idval;
			}else{
				$updatedata = "INSERT INTO `msg` (`lwd_parentid` , `admin_id` , `admin_name` , `lwd_title` , `lwd_type`,`lwd_status`,`lwd_content`,`lwd_time`)
							VALUES ( '$lwd_parentidval', '".$_SESSION["emplyeeUser"]["use_id"]."', '".$_SESSION["webAdmin"]["admin_name"]."', '$replylwd_titleval', '$lwd_typeval','$lwd_statusval','$relwd_contentval','$lwd_timeval') ";
			}
			
			
			$this -> db -> query_sql( $updatedata );
			
			$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?/msg/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?/msg/info/".$admin_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
		
}

//


$Leaveword = new Leaveword();

?>