<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Help
{
	function Help()
	{
		//$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 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  ".SQL_PREFIX."help as h , ".SQL_PREFIX."helpsort as s   WHERE h.hes_id = s.hes_id GROUP BY h.hel_id ORDER BY h.`hel_id` LIMIT  $LIMITnum , $pageSize ";
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."help as h  WHERE 1  ORDER BY `hel_id`  ";
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=help&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] );
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('help_tpl.html');
		
	}
	
	function add(  )
	{
		//$GLOBALS['Templ'] -> caching = true;
		//$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
		
		$this->getSort();

		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'hel_detail' );	//加载文本编辑器

		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=help&act=addinfo");
		$GLOBALS['Templ']->display('helpadd_tpl.html');
	}
	
	
	function getSort()
	{
		$sqlQuery = " SELECT hes_id, hes_name,hes_parentid  FROM  ".SQL_PREFIX."helpsort  WHERE 1 and hes_enabled = 1 GROUP BY hes_id ORDER BY `hes_list` limit 1000 ";
		
		$infosm = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$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;	
				}
		   }
		
		
		$GLOBALS['Templ']->assign('hsInfo',$hsInfo);
	}
	
	function addinfo()
	{
		$hel_titleval 	= $GLOBALS['Reque'] -> funpost("hel_title");
		$hel_authorval 	= $GLOBALS['Reque'] -> funpost("hel_author");
		
		
		//hel_mark
		$hes_idval 			= $GLOBALS['Reque'] -> funpost("hes_id");
		$hel_keywordval 	= $GLOBALS['Reque'] -> funpost("hel_keyword");
		$hel_markval 		= $GLOBALS['Reque'] -> funpost("hel_mark");
		$hel_descriptionval = $GLOBALS['Reque'] -> funpost("hel_description");
		$hel_detailval 		= $GLOBALS['Reque'] -> funpost("hel_detail");
		$hel_enabledval 	= $GLOBALS['Reque'] -> funpost("hel_enabled");
		$hel_listval 		= $GLOBALS['Reque'] -> funpost("hel_list");
		
		$hel_uptimeval = $hel_addtimeval 	= time();
		$hel_adminid = $_SESSION["emplyeeUser"]["use_id"];

		if($hel_titleval !='' and $hes_idval !='' and $hel_detailval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM ".SQL_PREFIX."help WHERE hel_title = '".$hel_titleval."' ORDER BY `hel_id` ";
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				$insertip ="INSERT INTO ".SQL_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')";
				
				$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=help&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=help&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=help&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$deletesql =" DELETE FROM ".SQL_PREFIX."help WHERE ".SQL_PREFIX."help.`hel_id` in ( $infoid )   ";
		
		$GLOBALS['MySql'] -> querySql($deletesql);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=help&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function show( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];

		$upshow = " UPDATE ".SQL_PREFIX."help SET hel_enabled = 1  WHERE ".SQL_PREFIX."help.`hel_id` in ( $infoid ) ";

		$GLOBALS['MySql'] -> querySql($upshow);
		
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_showsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=help&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function hide( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];

		
		$uphide = " UPDATE ".SQL_PREFIX."help SET hel_enabled = 0  WHERE ".SQL_PREFIX."help.`hel_id` in ( $infoid ) ";

		$GLOBALS['MySql'] -> querySql($uphide);
		
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_hidesusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=help&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	
	
	function info()
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$sqlQuery = " SELECT *  FROM ".SQL_PREFIX."help WHERE hel_id = '".$infoid."' ORDER BY `hel_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'hel_detail' ,$info["hel_detail"]);	//加载文本编辑器
		
		
		$this->getSort();
		
		
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=help&act=editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('helpedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$hel_idval 			= $GLOBALS['Reque'] -> funpost("hel_id");
		$hel_titleval 		= $GLOBALS['Reque'] -> funpost("hel_title");
		$hel_authorval 		= $GLOBALS['Reque'] -> funpost("hel_author");
		$hes_idval 			= $GLOBALS['Reque'] -> funpost("hes_id");
		$hel_keywordval 	= $GLOBALS['Reque'] -> funpost("hel_keyword");
		$hel_markval 		= $GLOBALS['Reque'] -> funpost("hel_mark");
		$hel_descriptionval = $GLOBALS['Reque'] -> funpost("hel_description");
		$hel_detailval 		= $GLOBALS['Reque'] -> funpost("hel_detail");
		$hel_enabledval 	= $GLOBALS['Reque'] -> funpost("hel_enabled");
		$hel_listval 		= $GLOBALS['Reque'] -> funpost("hel_list");
		
		$hel_uptimeval 		= time();

		if($hel_idval !='' and $hel_titleval !='' )
		{
			
			$updatesql = "UPDATE ".SQL_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."' ";
			
			
			$GLOBALS['MySql'] -> querySql( $updatesql );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=help&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=help&act=info&id=".$hel_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
		
}

//nmon_x86_rhel4

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

?>