<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Work
{
	function Work()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/login/actlogin");
	}
	
	function infolist(  )
	{
		//var_dump($strArray);
		
		$pageSize = 20 ;		$pageNumval 	= $GLOBALS['Reque'] -> reqval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}
		
		$endurl = '';
		$whereadd = "";
			
		$worksort_idval 	= $GLOBALS['Reque'] -> funpost("worksort_id");
		$keywordval 		= $GLOBALS['Reque'] -> funpost("keyword");
		
		if($strArray[1] !='' and $strArray[1] !='A')
		{
			$worksort_idval 	=  $strArray[1];
		}
		
		if($worksort_idval!='' and $worksort_idval !='A' )
		{ 
			 $endurl 	   .= '/'.$worksort_idval;
			 
			$sidsql  = " SELECT worksort_id FROM ".SQL_PREFIX."worksort WHERE worksort_parentid = ".$worksort_idval." or  worksort_id = ".$worksort_idval;
			 
		   $sortInfo 	  = $GLOBALS['MySql'] -> selectInfo( $sidsql );
			//var_dump( $sortInfo  );
			$sinid  = '';
			if($sortInfo!='')
			{
				foreach( $sortInfo as $skey => $sval )
				{
					if($skey==0)
					{
						$sinid = $sval["worksort_id"];
					}else{
						$sinid .= ','.$sval["worksort_id"];
					}
				}
				$whereadd .= " AND ( w.worksort_id IN ( ".$sinid." )  OR worksort2_id IN ( ".$sinid." ) OR worksort3_id IN  ( ".$sinid." )  )";
			}
		 }else{ 
		 	$endurl 	   .= '/A'; 	
		 }
		
		
		if($strArray[2] !='')
		{   
			$keywordval  	= urldecode($strArray[2]); 
		}
		if($keywordval!='')
		{ 	
			$endurl 	   .= '/'.urlencode($keywordval);
			$whereadd .= " AND ( w.work_name LIKE  '%".$keywordval."%' )";  
		}
		
		$sqlQuery = " SELECT w.work_id, w.work_name,s.worksort_name,w.work_progress , w.work_testdomain, w.work_domain , w.work_uptime   FROM  ".SQL_PREFIX."work as w , ".SQL_PREFIX."worksort  as s   WHERE s.worksort_id= w.worksort_id $whereadd GROUP BY w.work_id ORDER BY w.`work_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info 	 = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuerycount 	= " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."work  as w WHERE 1 $whereadd  ORDER BY w.`work_id`  ";
		
		$infocount 	= $GLOBALS['MySql'] -> selectOne($sqlQuerycount);
		
		$PageStr 	= $GLOBALS['Page']	-> buildPageStr( $url = '?load=work&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] , $endurl );
		
		
		$GLOBALS['Templ']->assign('worksort_idval',$worksort_idval);
		$GLOBALS['Templ']->assign('keywordval',$keywordval);
		
		$wsInfo = $this -> getSort();
		$GLOBALS['Templ']->assign('wsInfo',$wsInfo);

		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('work_tpl.html');
		
	}

	
	function getSort()
	{
		$sqlQuery = " SELECT worksort_id, worksort_name,worksort_parentid  FROM  ".SQL_PREFIX."worksort  WHERE 1 and worksort_enabled = 1 GROUP BY worksort_id ORDER BY `worksort_list` limit 1000 ";
		
		$infosm = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$wsInfo = array();
		foreach ($infosm as $rowkey => $rowval)
		{
				if($rowval["worksort_parentid"] == 0)
				{
					$wsInfo[$rowval["worksort_id"]]['worksort_id'] = $rowval["worksort_id"] ;
					$wsInfo[$rowval["worksort_id"]]['worksort_name'] = $rowval["worksort_name"] ;
					$wsInfo[$rowval["worksort_id"]]['worksort_parentid'] = $rowval["worksort_parentid"] ;
				}else{
					$wsInfo[$rowval["worksort_parentid"]]['array'][] = $rowval;	
				}
		}
		return $wsInfo;
		//$GLOBALS['Templ']->assign('asInfo',$asInfo);
	}



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

		$wsInfo = $this -> getSort();
		
		$GLOBALS['Templ']->assign('wsInfo',$wsInfo);
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'work_content' );	//加载文本编辑器

		
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/work/addinfo");
		$GLOBALS['Templ']->display('workadd_tpl.html');
	}
	
	function addinfo()
	{
		
		$work_nameval 		= $GLOBALS['Reque'] -> funpost("work_name");
		$worksort_idval 	= $GLOBALS['Reque'] -> funpost("worksort_id");
		$worksort2_idval 	= $GLOBALS['Reque'] -> funpost("worksort2_id");
		$worksort3_idval 	= $GLOBALS['Reque'] -> funpost("worksort3_id");
		$work_progressval 	= $GLOBALS['Reque'] -> funpost("work_progress");
		$work_testdomainval = $GLOBALS['Reque'] -> funpost("work_testdomain");	
		$work_domainval 	= $GLOBALS['Reque'] -> funpost("work_domain");
		$work_imgval 		= $GLOBALS['Reque'] -> funpost("work_img");
		
		// var_dump( $work_imgval );
		$work_img1val  = $work_imgval[1];
		$work_img2val  = $work_imgval[2];
		$work_img3val  = $work_imgval[3];
		$work_img4val  = $work_imgval[4];
		$work_img5val  = $work_imgval[5];
		$work_img6val  = $work_imgval[6];
		$work_img7val  = $work_imgval[7];
		
		$work_contentval 		= $GLOBALS['Reque'] -> funpost("work_content");
		
		
		$work_addtimeval 	= time();

		$admin_idval = $_SESSION["emplyeeUser"]["use_id"];
		
		if( $work_nameval !='' and $worksort_idval !='' and $work_progressval !='' and $work_testdomainval != '' )
		{
			$sqlQuery = " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."work  WHERE work_name = '".$work_nameval."' ORDER BY `work_id` ";
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["CNUM"] < 1 )
			{
				
				$insertsql =" INSERT INTO `".SQL_PREFIX."work` (`work_name` , `worksort_id` , `worksort2_id` ,`worksort3_id` ,`work_progress` , `work_testdomain` , `work_domain` , `work_img1` , `work_img2` , `work_img3`  , `work_img4` , `work_img5` , `work_img6` , `work_img7` ,`work_content`, `work_addtime`,`work_uptime`,`admin_id` ) VALUES (  '$work_nameval',  '$worksort_idval', '$worksort2_idval','$worksort3_idval','$work_progressval', '$work_testdomainval', '$work_domainval', '$work_img1val', '$work_img2val', '$work_img3val', '$work_img4val', '$work_img5val', '$work_img6val', '$work_img7val', '$work_contentval','$work_addtimeval','$work_uptimeval','$admin_idval')";
				
				$GLOBALS['MySql'] -> querySql($insertsql);
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php/work/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/work/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/work/add/");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$indel = implode(',', $delArray);
		$deletesql ="DELETE FROM `work` WHERE `".SQL_PREFIX."work`.`work_id` in ( $indel ) ";
		$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/work/infolist/");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info(  )
	{
		$infoid = $infoArray[0];
		
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."work  WHERE work_id = '".$infoid."' ORDER BY `work_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/work/editinfo");
		$GLOBALS['Templ'] -> assign('info',$info);
		
		$wsInfo = $this -> getSort();
		
		$GLOBALS['Templ']->assign('wsInfo',$wsInfo);
		
		//$GLOBALS['Templ']->assign('asInfo',$asInfo);

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

		$GLOBALS['Templ'] -> display('workedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$work_idval 		= $GLOBALS['Reque'] -> funpost("work_id");
		
		$work_nameval 		= $GLOBALS['Reque'] -> funpost("work_name");
		$worksort_idval 	= $GLOBALS['Reque'] -> funpost("worksort_id");
		$worksort2_idval 	= $GLOBALS['Reque'] -> funpost("worksort2_id");
		$worksort3_idval 	= $GLOBALS['Reque'] -> funpost("worksort3_id");
		$work_progressval 	= $GLOBALS['Reque'] -> funpost("work_progress");
		$work_testdomainval = $GLOBALS['Reque'] -> funpost("work_testdomain");	
		$work_domainval 	= $GLOBALS['Reque'] -> funpost("work_domain");
		$work_imgval 		= $GLOBALS['Reque'] -> funpost("work_img");
		
		// var_dump( $work_imgval );
		$work_img1val  = $work_imgval[1];
		$work_img2val  = $work_imgval[2];
		$work_img3val  = $work_imgval[3];
		$work_img4val  = $work_imgval[4];
		$work_img5val  = $work_imgval[5];
		$work_img6val  = $work_imgval[6];
		$work_img7val  = $work_imgval[7];
		
		$work_contentval 		= $GLOBALS['Reque'] -> funpost("work_content");
		

		
		if($work_idval !='' and  $work_nameval !='' and $worksort_idval !='' and $work_progressval !='' and $work_contentval != '' )
		{

			$updatesql = "UPDATE `".SQL_PREFIX."work` SET  work_name = '".$work_nameval."' , worksort_id = '".$worksort_idval."' , worksort2_id = '".$worksort2_idval."', worksort3_id = '".$worksort3_idval."', work_progress = '".$work_progressval."', work_testdomain = '".$work_testdomainval."', work_domain = '".$work_domainval."', work_img1 = '".$work_img1val."', work_img2 = '".$work_img2val."', work_img3 = '".$work_img3val."', work_img4 = '".$work_img4val."', work_img5 = '".$work_img5val."', work_img6 = '".$work_img6val."' , work_img7 = '".$work_img7val."' , work_content = '".$work_contentval."' WHERE  work_id = '".$work_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/work/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/work/info/".$work_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
		
}

//nmon_x86_rhel4

$Work = new Work();

?>