<?php
/**
 *----------------------------------------------------------------------------*
 * 版权所有 2005-2010 GV32.COM，并保留所有权利。
 * 网站地址: http://www.gv32.com；
 * 作者: GV32.COM
 *----------------------------------------------------------------------------*
**/
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Config
{
	function Config()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/login/actlogin");
	}
	
	function infolist(  )
	{

		$sqlQuery = " SELECT *  FROM ".SQL_PREFIX."configsys WHERE cfs_type ='web' GROUP BY cfs_id ORDER BY `cfs_id`  ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);

		foreach( $info as $key => $val )
		{
			$reArray[$val["cfs_codestr"]] = $val;
		}
		
		//var_dump($reArray);
		$GLOBALS['Templ']->assign('reArray',$reArray);
		$GLOBALS['Templ']->display('config_tpl.html');
		
	}
	
	function editinfo( )
	{	
	
		$webnameval 			= $GLOBALS['Reque'] -> funpost("webname");
		$webtitleval 			= $GLOBALS['Reque'] -> funpost("webtitle");
		$webkeywordval 			= $GLOBALS['Reque'] -> funpost("webkeyword");
		$webdescriptionval		= $GLOBALS['Reque'] -> funpost("webdescription");
		$webadminval 			= $GLOBALS['Reque'] -> funpost("webadmin");
		$webmailval 			= $GLOBALS['Reque'] -> funpost("webmail");
		$webqqval				= $GLOBALS['Reque'] -> funpost("webqq");
		$webphoteval 			= $GLOBALS['Reque'] -> funpost("webphote");
		$webaddressval 			= $GLOBALS['Reque'] -> funpost("webaddress");
		$webcloseval 			= $GLOBALS['Reque'] -> funpost("webclose");
		$webclosevalueval 		= $GLOBALS['Reque'] -> funpost("webclosevalue");
		$weblogoval 			= $GLOBALS['Reque'] -> funpost("weblogo");
		$webregval				= $GLOBALS['Reque'] -> funpost("webreg");
		$webcertificateval 		= $GLOBALS['Reque'] -> funpost("webcertificate");
		$webserachkeywordval 	= $GLOBALS['Reque'] -> funpost("webserachkeyword");
		
		$webtmpval				= $GLOBALS['Reque'] -> funpost("webtmp");
		$webtmptimeval 			= $GLOBALS['Reque'] -> funpost("webtmptime");

		$webhtmlval				= $GLOBALS['Reque'] -> funpost("webhtml");

		//var_dump($webtitleval);
		
		if($webnameval !='' and $webtitleval !='' )
		{
			
			$upsql = '';
			$uparray = array('webname'=>$webnameval, 'webtitle'=>$webtitleval, 'webkeyword'=>$webkeywordval,'webdescription'=>$webdescriptionval,
							'webadmin'=>$webadminval, 'webmail'=>$webmailval, 'webqq'=>$webqqval,
							'webphote'=>$webphoteval, 'webaddress'=>$webaddressval, 'webclose'=>$webcloseval,
							'webclosevalue'=>$webclosevalueval, 'weblogo'=>$weblogoval, 'webreg'=>$webregval,
							'webcertificate'=>$webcertificateval, 'webserachkeyword'=>$webserachkeywordval, 'webtmp'=>$webtmpval, 'webtmptime'=>$webtmptimeval, 
							'webhtml'=>$webhtmlval
							);		

			foreach($uparray as $key => $val)
			{
				if($val!='')
				{
					$upsql = '';
					$upsql = "UPDATE ".SQL_PREFIX."configsys  set  cfs_value  = '".$val."'   WHERE  cfs_codestr = '".$key."' and cfs_type ='web' ";
					$GLOBALS['MySql'] -> querySql( $upsql );
				}
			}
			//exit();
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=config&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=config&act=infolist");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	function temlist(  )
	{

		
		$sqlQuery = " SELECT *  FROM ".SQL_PREFIX."configsys WHERE cfs_type ='temp' GROUP BY cfs_id ORDER BY `cfs_id`  ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
				
		$GLOBALS['Templ']->assign('info',$info);
		
		$GLOBALS['Templ']->display('temp_tpl.html');	
	}
	
	
	//添加新查询模板
	function selecttem()
	{
		//查询数据库中模板数量，及查询目录下文件是否存在。
		
		$sqlQuery = " SELECT *  FROM ".SQL_PREFIX."configsys WHERE cfs_type ='temp' GROUP BY cfs_id ORDER BY `cfs_id`  ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$iskeyArray = array();
		foreach( (array)$info as $ikey => $ival )
		{
			$iskeyArray[] = $ival["cfs_value"];
			
		}
		//查询目录下所有文件夹
		$dir = DOCUMENT_DIR."templates/www";
		
		$dirlist = $GLOBALS['Helpe'] -> getdirs( $dir );
 
 		$isnew = false ;
		foreach((array)$dirlist as $dkey => $dval)
		{	
			if(in_array($dval , $iskeyArray))
			{
				 
			
			}else{
				$isnew = true ; 
				//可添加目录，不存在库中模板
				if(is_file($dir."/".$dval."/default.xml"))
				{
					//echo $dir."/".$dval."/default.xml";
					$recfs = $this -> readxml($dir."/".$dval."/default.xml");
					if($recfs["cfs_name"]!='')
					{
						$sqlinsert = "INSERT INTO `".SQL_PREFIX."configsys` (  `cfs_name` , `cfs_codestr` , `cfs_value` , `cfs_type` )VALUES (  '".$recfs["cfs_name"]."', 'template', '".$dval."', 'temp') ";
						
						$GLOBALS['MySql'] -> querySql( $sqlinsert );
					}
					
				}
				//echo 'out'.$dval;
			
			}
			//echo '<br>';
		}
		if($isnew == false)
		{
			$GLOBALS['_LANG']['bd_tempsssusse']	= $GLOBALS['_LANG']['bd_tempnone'] .$dir."/<br>";
			 
		}
 
		
		$GLOBALS['Templ']->assign('info',$info);
		
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_tempsssusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=config&act=temlist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
		
	}
	
	function readxml($fileName = '')
	{
	
		$file = fopen($fileName, 'r'); 
		while( $data = fread( $file, 4096 ) )
		{ 
			$xml .= $data; 
		} 
		fclose( $file ); 
		
		// 上面读取数据 
		preg_match_all( "/\<copyright\>(.*?)\<\/copyright\>/s", $xml, $humans ); //匹配最外层标签里面的内容 
		
 
		preg_match_all( '/\<title\>(.*?)\<\/title\>/', $humans[1][0], $title ); //匹配出名字 
		//var_dump($name);
		preg_match_all( "/\<link\>(.*?)\<\/link\>/", $humans[1][0], $link ); //匹配出性别 
		preg_match_all( "/\<version\>(.*?)\<\/version\>/", $humans[1][0], $version ); //匹配出年龄 

	 	$recfs["cfs_name"] 		= $title[1][0] ;
		//$recfs["cfs_codestr"] 	= $link[1][0] ;
		//$recfs["cfs_value"] 	= $version[1][0] ;
		
		return $recfs;	
	
	}

	
	
	function edittemp(  )
	{
		$cfs_codestrval = $GLOBALS['Reque'] -> funpost("cfs_codestr");
		
		$upsqldel = "UPDATE ".SQL_PREFIX."configsys  set  cfs_codestr  = 'template'   WHERE  cfs_id <> '".$cfs_codestrval."' and cfs_type = 'temp' ";
		
		$GLOBALS['MySql'] -> querySql( $upsqldel );
		
		$upsql = "UPDATE ".SQL_PREFIX."configsys  set  cfs_codestr  = 'default'   WHERE  cfs_id = '".$cfs_codestrval."' and cfs_type = 'temp' ";
		$GLOBALS['MySql'] -> querySql( $upsql );
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=config&act=temlist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
		
		
	}
		
}

$Config = new Config();

?>