<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Artlice
{
	function Artlice()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=login/actlogin");
	}
	
	function infolist()
	{
		$pageSize = 20 ;
		
		$ars_idval 		= $GLOBALS['Reque'] -> reqval["ars_id"];
		$keywordval 	= $GLOBALS['Reque'] -> reqval["keyword"];
		$pageNumval 	= $GLOBALS['Reque'] -> reqval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}

		
		if($ars_idval!='' and $ars_idval !='A' )
		{ 
			
			$endArray["ars_id"] = $ars_idval;
			 
			$sidsql  = " SELECT ars_id FROM ".SQL_PREFIX."artsort WHERE ars_parentid = ".$ars_idval." or  ars_id = ".$ars_idval;
			 
		    $sortInfo 	  = $GLOBALS['MySql'] -> selectInfo( $sidsql );
			//var_dump( $sortInfo  );
			$sinid  = '';
			if($sortInfo!='')
			{
				foreach( $sortInfo as $skey => $sval )
				{
					if($skey==0)
					{
						$sinid = $sval["ars_id"];
					}else{
						$sinid .= ','.$sval["ars_id"];
					}
				}
				$whereadd .= " AND ( a.ars_id IN ( ".$sinid." ) )";
			}
		 }else{ 
		 	$endurl 	   .= '&ars_id=A'; 	
		 }

		
		if($GLOBALS['Reque'] -> getval["keyword"] !='')
		{   
			$keywordval 	= $GLOBALS['Reque'] -> getval["keyword"];
			$keywordval  	= urldecode($keywordval); 
		}
		if($keywordval!='')
		{ 	
			$endArray["keyword"] =$keywordval;
			
			$endurl 	   .= '&keyword='.urlencode($keywordval);
			$whereadd .= " AND ( a.art_title LIKE  '%".$keywordval."%' )";  
		}
		
		//listval 字段名称
		//listtype 1'',2'DESC'
		$listval  = $GLOBALS['Reque'] -> getval["listval"];
		$listtype = $GLOBALS['Reque'] -> getval["listtype"];
		
		
		$orderbyval = "";
		
		if($listval!='' and $listtype =='DESC' )
		{
			$endArray["listtype"] = 'DESC';
			$endArray["listval"]  = $listval;
			$orderbyval = $listval ."  DESC ";
			$listhtml = '';	//反向排序参数
			
		}elseif($listval!='' )
		{
			$orderbyval = $listval;
			$listhtml = 'DESC';
			
			$endArray["listtype"] = '';
			$endArray["listval"]  = $listval;

		}else{
			$endArray["listtype"] = 'DESC';
			$endArray["listval"]  = 'art_uptime';
			$orderbyval = " a.art_uptime DESC , `art_id` DESC ";	
		}
		
		//echo $whereadd;
		//序号 	标题 	文章分类 	浏览量 	是否显示 	更新时间 	排序
		
		$sqlQuery = " SELECT a.art_id, a.art_title, a.art_count , a.ars_id , a.art_enabled ,a.art_uptime ,a.art_list,a.art_sysfile  FROM  ".SQL_PREFIX."artlice as a    WHERE 1  $whereadd  GROUP BY art_id  ORDER BY  $orderbyval LIMIT  $LIMITnum , $pageSize ";
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."artlice as a   WHERE 1 $whereadd  ORDER BY a.`art_id`  ";
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		
		//var_dump($info);
		
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=artlice&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] , $endArray );
		
		$this -> getSort();
		
		$GLOBALS['Templ']->assign('listhtml',$listhtml);
		$GLOBALS['Templ']->assign('listval',$listval);
		$GLOBALS['Templ']->assign('listtype',$listtype);
		
		$GLOBALS['Templ']->assign('ars_idval',$ars_idval);
		$GLOBALS['Templ']->assign('keywordval',$keywordval);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('artlice_tpl.html');

	}
	
	function add(  )
	{
		//$GLOBALS['Templ'] -> caching = true;
		//$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24

		$this->getSort();
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'art_detail' );	//加载文本编辑器
		
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=artlice&act=addinfo");
		$GLOBALS['Templ']->display('artliceadd_tpl.html');
	}
	
	
	function addinfo()
	{
		$art_titleval 		= $GLOBALS['Reque'] -> funpost("art_title");
		$art_pinyinval 		= $GLOBALS['Reque'] -> funpost("art_pinyin");
		$art_authorval 		= $GLOBALS['Reque'] -> funpost("art_author");
		$ars_idval 			= $GLOBALS['Reque'] -> funpost("ars_id");
		$art_keywordval 	= $GLOBALS['Reque'] -> funpost("art_keyword");
		$art_descriptionval = $_POST["art_description"];  //$GLOBALS['Reque'] -> funpost("art_description");
		$art_detailval 		= $GLOBALS['Reque'] -> funpost("art_detail");
		$art_picval 		= $GLOBALS['Reque'] -> funpost("art_pic");
		$art_fileval 		= $GLOBALS['Reque'] -> funpost("art_file");
		$art_enabledval 	= $GLOBALS['Reque'] -> funpost("art_enabled");
		$art_listval 		= $GLOBALS['Reque'] -> funpost("art_list");
		
		$art_uptimeval = $art_addtimeval 	= time();
		$art_adminid = $_SESSION["emplyeeUser"]["use_id"];
		//art_title 	art_author 	ars_id 	art_addtime 	art_keyword 	art_description 	art_detail 	art_pic 	art_file 	 	art_enabled 
		//art_adminid 	art_list 	art_uptime
		
		if($art_titleval !='' and $ars_idval !='' and $art_detailval !='' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."artlice  WHERE art_title = '".$art_titleval."' ORDER BY `art_id` ";
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				$insertip ="INSERT INTO `".SQL_PREFIX."artlice` (`art_title` , `art_pinyin` ,`art_author` , `ars_id` , `art_keyword` , `art_description` , `art_detail` , `art_pic` , `art_file` , `art_enabled`, `art_list`,`art_uptime`,`art_addtime`,`art_adminid`) VALUES (  '$art_titleval', '$art_pinyinval','$art_authorval', '$ars_idval', '$art_keywordval', '$art_descriptionval', '$art_detailval', '$art_picval', '$art_fileval', '$art_enabledval', '$art_listval' ,'$art_uptimeval','$art_addtimeval','$art_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=artlice&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=artlice&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=artlice&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	
	function getSort()
	{
		
		$sqlQuery = " SELECT ars_id, ars_name,ars_parentid  FROM  ".SQL_PREFIX."artsort  WHERE 1 and ars_enabled = 1 GROUP BY ars_id ORDER BY `ars_list` limit 1000 ";
		
		$infosm = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$asInfo = array();
		foreach((array)$infosm as $rowkey => $rowval)
		{
				if($rowval["ars_parentid"] == 0)
				{
					$asInfo[$rowval["ars_id"]]['ars_id'] 		= $rowval["ars_id"] ;
					$asInfo[$rowval["ars_id"]]['ars_name'] 		= $rowval["ars_name"] ;
					$asInfo[$rowval["ars_id"]]['ars_parentid']  = $rowval["ars_parentid"] ;
				}else{
					$asInfo[$rowval["ars_parentid"]]['array'][] = $rowval;	
				}
				
				$asInfoval[$rowval["ars_id"]] = $rowval["ars_name"] ;
		}
		//var_dump($asInfoval);
		$GLOBALS['Templ']->assign('asInfoval',$asInfoval);		//列排表显示使用
		
		$GLOBALS['Templ']->assign('asInfo',$asInfo);
		return $asInfo;
	}

	
	
	
	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$deletesql ="DELETE FROM `".SQL_PREFIX."artlice`   WHERE  `art_id` in ( $infoid ) AND art_sysfile = '' ";
		
		@$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=artlice&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function show( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$upshow = " UPDATE `".SQL_PREFIX."artlice` SET art_enabled = 1  WHERE  `art_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=artlice&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function hide( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$uphide = " UPDATE `".SQL_PREFIX."artlice` SET art_enabled = 0  WHERE  `art_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=artlice&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function info(  )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."artlice  WHERE art_id = '".$infoid."' ORDER BY `art_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);

		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'art_detail' ,$textValue = $info["art_detail"] );	//加载文本编辑器

		
		$this->getSort();
		
		
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=artlice&act=editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('artliceedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$art_idval 			= $GLOBALS['Reque'] -> funpost("art_id");
		$art_titleval 		= $GLOBALS['Reque'] -> funpost("art_title");
		$art_pinyinval 		= $GLOBALS['Reque'] -> funpost("art_pinyin");
		$art_authorval 		= $GLOBALS['Reque'] -> funpost("art_author");
		$ars_idval 			= $GLOBALS['Reque'] -> funpost("ars_id");
		$art_keywordval 	= $GLOBALS['Reque'] -> funpost("art_keyword");
		$art_descriptionval = $_POST["art_description"];   //$art_descriptionval = $GLOBALS['Reque'] -> funpost("art_description");
		$art_detailval 		= $GLOBALS['Reque'] -> funpost("art_detail");
		$art_picval 		= $GLOBALS['Reque'] -> funpost("art_pic");
		$art_fileval 		= $GLOBALS['Reque'] -> funpost("art_file");
		$art_enabledval 	= $GLOBALS['Reque'] -> funpost("art_enabled");
		$art_listval 		= $GLOBALS['Reque'] -> funpost("art_list");
		
		$art_uptimeval 		= time();

		if($art_idval !='' and $art_titleval !='' )
		{
			
			$updatesql = "UPDATE `".SQL_PREFIX."artlice` SET  art_title = '".$art_titleval."' , art_pinyin = '".$art_pinyinval."' , art_author = '".$art_authorval."' , ars_id = '".$ars_idval."' , art_keyword = '".$art_keywordval."' , art_description = '".$art_descriptionval."' , art_detail = '".$art_detailval."' , art_pic = '".$art_picval."' , art_file = '".$art_fileval."' , art_enabled = '".$art_enabledval."' , art_list = '".$art_listval."' , art_uptime = '".$art_uptimeval."'  WHERE  art_id = '".$art_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=artlice&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=artlice&act=info&id=".$art_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}

	}
		
}

//nmon_x86_rhel4

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

?>