<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Help
{
	function Help()
	{
		//$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 h.hel_id, h.hel_title, s.hes_name, h.hel_count , h.hel_enabled ,h.hel_uptime ,h.hel_list,	h.hel_enabled  FROM  ".$this -> db -> prefix."help as h , ".$this -> db -> prefix."helpsort as s   WHERE h.hes_id = s.hes_id GROUP BY h.hel_id ORDER BY h.`hel_id` LIMIT  $limit_num , $page_size ";
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."help as h  WHERE 1  ORDER BY `hel_id`  ";
		$infocount = $this -> db -> select_one($sql_query);
		
		//var_dump($info);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=help&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('help.tpl');
		
	}
	
	function add(  )
	{
		//$this -> view ->  caching = true;
		//$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24
		
		$this->getSort();

		$this -> helper -> load_ckeditor( 'hel_detail' );	//加载文本编辑器

		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=help&act=add_info");
		$this -> view -> display('helpadd.tpl');
	}
	
	
	function getSort()
	{
		$sql_query = " SELECT hes_id, hes_name,hes_parentid  FROM  ".$this -> db -> prefix."helpsort  WHERE 1 and hes_enabled = 1 GROUP BY hes_id ORDER BY `hes_list` limit 1000 ";
		
		$infosm = $this -> db -> select_info($sql_query);
		
		$hsInfo = array();
		   foreach ($infosm as $rowkey => $rowval)
		   {
		   		if($rowval["hes_parentid"] == 0)
				{
				
					$hsInfo[$rowval["hes_id"]]['hes_id'] = $rowval["hes_id"] ;
					$hsInfo[$rowval["hes_id"]]['hes_name'] = $rowval["hes_name"] ;
					$hsInfo[$rowval["hes_id"]]['hes_parentid'] = $rowval["hes_parentid"] ;
				}else{
					$hsInfo[$rowval["hes_parentid"]]['array'][] = $rowval;	
				}
		   }
		
		
		$this -> view -> assign('hsInfo',$hsInfo);
	}
	
	function add_info()
	{
		$hel_titleval 	= $this -> input ->  funpost("hel_title");
		$hel_authorval 	= $this -> input ->  funpost("hel_author");
		
		
		//hel_mark
		$hes_idval 			= $this -> input ->  funpost("hes_id");
		$hel_keywordval 	= $this -> input ->  funpost("hel_keyword");
		$hel_markval 		= $this -> input ->  funpost("hel_mark");
		$hel_descriptionval = $this -> input ->  funpost("hel_description");
		$hel_detailval 		= $this -> input ->  funpost("hel_detail");
		$hel_enabledval 	= $this -> input ->  funpost("hel_enabled");
		$hel_listval 		= $this -> input ->  funpost("hel_list");
		
		$hel_uptimeval = $hel_addtimeval 	= time();
		$hel_adminid = $_SESSION["emplyeeUser"]["use_id"];

		if($hel_titleval !='' and $hes_idval !='' and $hel_detailval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM ".$this -> db -> prefix."help WHERE hel_title = '".$hel_titleval."' ORDER BY `hel_id` ";
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{
				$insertip ="INSERT INTO ".$this -> db -> prefix."help (`hel_title` , `hes_id` , `hel_keyword` , `hel_mark`, `hel_description` , `hel_detail` , `hel_enabled`, `hel_list`,`hel_uptime`,`hel_addtime`,`hel_adminid`) VALUES (  '$hel_titleval', '$hes_idval', '$hel_keywordval', '$hel_markval', '$hel_descriptionval', '$hel_detailval',  '$hel_enabledval', '$hel_listval' ,'$hel_uptimeval','$hel_addtimeval','$hel_adminid')";
				
				$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=help&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=help&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=help&act=add");
			$this -> view ->  display('suggestion.tpl');	
		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $this -> input ->  get["id"];
		$deletesql =" DELETE FROM ".$this -> db -> prefix."help WHERE ".$this -> db -> prefix."help.`hel_id` in ( $infoid )   ";
		
		$this -> db -> query_sql($deletesql);
		$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=help&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	
	function show( )
	{
		$infoid = $this -> input ->  get["id"];

		$upshow = " UPDATE ".$this -> db -> prefix."help SET hel_enabled = 1  WHERE ".$this -> db -> prefix."help.`hel_id` in ( $infoid ) ";

		$this -> db -> query_sql($upshow);
		
		$this -> view ->  assign('info_title',$_LANG['bd_showsusse']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=help&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function hide( )
	{
		$infoid = $this -> input ->  get["id"];

		
		$uphide = " UPDATE ".$this -> db -> prefix."help SET hel_enabled = 0  WHERE ".$this -> db -> prefix."help.`hel_id` in ( $infoid ) ";

		$this -> db -> query_sql($uphide);
		
		$this -> view ->  assign('info_title',$_LANG['bd_hidesusse']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=help&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	
	
	
	function info()
	{
		$infoid = $this -> input ->  get["id"];
		
		$sql_query = " SELECT *  FROM ".$this -> db -> prefix."help WHERE hel_id = '".$infoid."' ORDER BY `hel_id` ";
		$info = $this -> db -> select_one($sql_query);
		
		
		$this -> helper -> load_ckeditor( 'hel_detail' ,$info["hel_detail"]);	//加载文本编辑器
		
		
		$this->getSort();
		
		
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=help&act=edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('helpedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$hel_idval 			= $this -> input ->  funpost("hel_id");
		$hel_titleval 		= $this -> input ->  funpost("hel_title");
		$hel_authorval 		= $this -> input ->  funpost("hel_author");
		$hes_idval 			= $this -> input ->  funpost("hes_id");
		$hel_keywordval 	= $this -> input ->  funpost("hel_keyword");
		$hel_markval 		= $this -> input ->  funpost("hel_mark");
		$hel_descriptionval = $this -> input ->  funpost("hel_description");
		$hel_detailval 		= $this -> input ->  funpost("hel_detail");
		$hel_enabledval 	= $this -> input ->  funpost("hel_enabled");
		$hel_listval 		= $this -> input ->  funpost("hel_list");
		
		$hel_uptimeval 		= time();

		if($hel_idval !='' and $hel_titleval !='' )
		{
			
			$updatesql = "UPDATE ".$this -> db -> prefix."help SET  hel_title = '".$hel_titleval."' ,   hes_id = '".$hes_idval."' , hel_keyword = '".$hel_keywordval."' ,hel_mark = '".$hel_markval."' , hel_description = '".$hel_descriptionval."' , hel_detail = '".$hel_detailval."' , hel_enabled = '".$hel_enabledval."' , hel_list = '".$hel_listval."' , hel_uptime = '".$hel_uptimeval."'  WHERE  hel_id = '".$hel_idval."' ";
			
			
			$this -> db -> query_sql( $updatesql );
			
			$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=help&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=help&act=info&id=".$hel_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
		
}

//

$Help = new Help();
//include_once("../application/ckeditor/ckeditor_php5.php");

?>