<?
error_reporting ( 0 );
require_once('inc.php');
require_once('../inc/config.php');
function getSubDirs($dir) 
{
	$subdirs = array();
	if(!$dh = opendir($dir)) 
		return $subdirs;
	$i = 0;
	while ($f = readdir($dh)) 
	{
     	if($f =='.' || $f =='..') 
			continue;
		//如果只要子目录名, path = $f;
 		//$path = $dir.'/'.$f;  
		$path = $f;
		$subdirs[$i] = $path;
		$i++;
	}
	return $subdirs;
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link rel="stylesheet" type="text/css" href="css/admin.css">
<link href="css/jquery.css" rel="stylesheet" type="text/css">
<link href="css/base.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<style type="text/css">
.error_msg{
	color:red;
}
.success_msg{
	color:green;
}


</style>

<script type="text/javascript">
function tab(no,n){
	for(var i=1;i<=n;i++){
		$('#config'+i).hide();
	}
	$('#config'+no).show();
} 
</script>
</head>
<body> 
<?
if ($_GET ['id'] == 'man') {
	?>
<div class="right">
 <? include "welcome.php";?>
  <div class="right_main">
<table width="98%" border="0" cellpadding="4" cellspacing="1"class="tableoutline"><tr class="tb_head"><td><h2>操作导航：</h2></td></tr><tr class="firstalt"><td><ul class="do_nav"><li><a href="javascript:" onClick="tab(1,6);">网站设置</a></li><li><a href="javascript:" onClick="tab(3,6);">评论设置</a></li><li><a href="javascript:" onClick="tab(2,6);">友情链接</a></li></ul></td></tr></table>
<table width="98%" border="0" cellpadding="4" cellspacing="1"
	class="tableoutline">
	<form action="?id=save" method="post">
	<tbody id="config1">
		<tr nowrap class="tb_head">
			<td colspan="2">
			<h2>网站信息：</h2>			</td>
		</tr>
		<tr nowrap class="firstalt">
			<td width="260"><b>网站标题</b><br>			</td>
			<td><input type="text" name="webtitle" size="25" maxlength="50" value="<?=$webtitle;?>" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
		</tr>
		
		
		<tr nowrap class="firstalt">
			<td width="260"><b>网站域名</b><br>
		    <font color="#666666">域名请以<font color="red">http://</font>开头,结尾以<font color="red">斜杠&quot;/&quot;</font>结尾</font></td>
			<td><input type="text" name="url" size="25" maxlength="50" value="<?=$url;?>" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ><a id="web_url_msg"></a></td>
		</tr>
		
		<tr nowrap class="firstalt">
			<td width="260"><b>二级目录</b><br>
			<font color="#666666">注意以<font color="red">斜杠"/"</font>结尾,根目录请留空</font></td>
			<td><input type="text" name="erji" size="25" maxlength="50" value="<?=$erji;?>" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
		</tr>
		<tr nowrap class="firstalt">
			<td width="260"><b>默认风格</b><br>
			<font color="#666666">网站风格文件夹.位于templets目录下</font></td>
			<td><!----input type="text" name="template" size="25" maxlength="50" value="<?=$template;?>" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ---->
			<select name="template" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" >
				<option value="default" <?
	if ($template == "default")
		echo " selected";?>>默认模板</option>
				<option value="blue" <?
	if ($template == "blue")
		echo " selected";?>>蓝色模板</option>
			</select>			</td>
		</tr>
		
		


		<tr nowrap class="firstalt">
			<td width="260"><b>关键字</b><br>
			<font color="#666666">SEO关键字描述</font></td>
			<td><input name="keywords" type="text" value="<?=$keywords;?>"
				size="55" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
		</tr>
		<tr nowrap class="firstalt" >
			<td width="260"><b>网站描述</b><br>
			<font color="#666666">SEO网页内容信息描述</font></td>
			<td><textarea name="description" cols="80" style="height: 70px; width: 350px" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ><?=$description;?></textarea></td>
		</tr>
	
		
		
		<tr class="firstalt">
			<td width="260" valign="top"><b>统计代码</b><br>
			<font color="#666666">流量统计代码<br><!--<font color="red">注意：把代码中的双引号改成单引号</font>--></font></td>
			<td><textarea name="tongji" cols="80"
				style="height: 70px; width: 350px" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ><?=$tongji;?></textarea></td>
		</tr>
		<tr class="firstalt">
			<td width="260" valign="top"><b>底部版权代码</b><br>
			<font color="#666666">网站底部版权信息</font><font color="#666666"><br>
			<!--<font color="red">注意：把代码中的双引号改成单引号</font>--></font></td>
			<td><textarea name="banquan" cols="80"
				style="height: 70px; width: 350px" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ><?=$banquan;?></textarea></td>
		</tr>

		<tr nowrap class="firstalt">
			<td width="260"><b>备案信息</b><br>
			<font color="#666666">填写贵站的ICP备案信息</font></td>
			<td><input type="text" name="beian" size="25" value="<?=$beian;?>" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
		</tr>
		<tr nowrap class="firstalt">
			<td width="260"><b>蜘蛛访问记录开关</b><br>
			</td>
			<td><select name="zhizhu" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" >
				<option value="1" <?
	if ($zhizhu == "1")
		echo " selected";?>>开启</option>
				<option value="0" <?
	if ($zhizhu == "0")
		echo " selected";?>>关闭</option>
			</select></td>
		</tr>
		<tr nowrap class="tb_head">
			<td colspan="2">
			<h2>页面设置：</h2>			</td>
		</tr>
		<tr nowrap class="firstalt">
			<td width="260"><b>伪原创开关</b><br>
			<font color="#666666">开启伪原创有利于seo</font></td>
			<td><select name="wyc" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" >
				<option value="on" <?
	if ($wyc == "on")
		echo " selected";?>>开启</option>
				<option value="off" <?
	if ($wyc == "off")
		echo " selected";?>>关闭</option>
			</select></td>
		</tr>
		
		
		
		<!--<tr nowrap class="firstalt">
			<td width="260"><b>采集方式</b><br>
			<font color="#666666">服务器不支持采集的时候,可以尝试更换采集方式</font></td>
			<td><select name="caiji" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" >
				<option value="curl_init" <?
	if ($caiji == "curl_init")
		echo " selected";?>>curl_init</option>
				<option value="fsock" <?
	if ($caiji == "fsock")
		echo " selected";?>>fsockopen</option>
				<option value="fsock" <?
	if ($caiji == "pfsock")
		echo " selected";?>>pfsockopen</option>
				<option value="file_get_contents" <?
	if ($caiji == "file_get_contents")
		echo " selected";?>>file_get_contents</option>
			</select></td>
		</tr>-->
	</tbody>
       <tbody id="config3" style="display: none">
		<tr nowrap class="tb_head">
			<td colspan="4">
			<h2>畅言评论设置：</h2>			</td>
		</tr>
		<tr nowrap class="firstalt">
			<td width="260"><b>是否开启评论功能</b><br>
			<font color="#666666">开启问题页评论功能</font></td>
			<td><select name="pinglun"onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" >
				<option value="1" <?
	if ($pinglun == "1")
		echo " selected";?>>开启</option>
				<option value="0" <?
	if ($pinglun == "0")
		echo " selected";?>>关闭</option>
			</select></td>
		</tr>
		<tr nowrap class="firstalt">
			<td width="260"><b>畅言appid：</b><br>			</td>
			<td><input type="text" name="appid" size="25" maxlength="50" value="<?=$appid;?>" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
		</tr>
		
		
		<tr nowrap class="firstalt">
			<td width="260"><b>畅言conf：</b><br>
			<font color="#666666">畅言申请地址：<a href="http://changyan.kuaizhan.com/" target="_blank">http://changyan.kuaizhan.com/</a></td>
			<td><input type="text" name="conf" size="25" maxlength="50" value="<?=$conf;?>" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
		</tr>
		
		
		
		
		
		
		
	</tbody>
	<tbody id="config2" style="display: none">
		<tr nowrap class="tb_head">
			<td colspan="3">
			<h2>友情链接：</h2>			</td>
		</tr>
		<tr nowrap class="firstalt">
			<td width="260" align="center"><b>网站名称</b><br>			</td>
			<td style="padding-left: 120px;"><b>网站地址</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>顺序</b></td>
		</tr>
		<?
	$link = preg_replace ( '/;/', "", $link, 1 );
	$link = explode ( ";", $link );
	$coulink = count ( $link );
	$n = 0;
	for($i = 0; $i < $coulink; $i ++) {
		if (! empty ( $link [$i] )) {
			$sitelink = explode ( "|", $link [$i] );
		}
		?>
        <tr nowrap class="firstalt">
			<td width="260" align="center"><input
				name="link_name[<?=$n;?>]" type="text" value="<?=str_replace ( "
	\r\n", "", $sitelink [0] );?>"
				maxlength="50" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
			<td style="padding-left: 70px;"><input
				name="link_url[<?=$n;?>]" type="text" value="<?
		if (empty ( $sitelink [0] ) && empty ( $sitelink [1] )) {
			echo "http://";
		} else {
		}
		?><?=str_replace ( "
	\r\n", "", $sitelink [1] );?>"
				size="30" maxlength="250" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
				name="link_order[<?=$n;?>]" type="text" value="<?=$n;?>"
				size="5" maxlength="5" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
		</tr>
<?
		$n ++;
	}
	?>
<?php

	if (! empty ( $sitelink [0] ) && ! empty ( $sitelink [1] )) {
		?>
<tr nowrap class="firstalt">
			<td width="260" style="padding-left: 32px;">添加&nbsp;&nbsp;&nbsp;<input
				name="link_name_sub" type="text" maxlength="50" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
			<td style="padding-left: 70px;"><input name="link_url_sub"
				type="text" size="30" value="http://" maxlength="250" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
				name="link_order_sub" type="text" size="5" value="50" maxlength="5" onFocus="this.style.borderColor='#00CC00'" onBlur="this.style.borderColor='#dcdcdc'" ></td>
		</tr>
<?php
	} else {
	}
	?>
      </tbody>

	

	<tr class="firstalt">
		<td colspan="2" align="center"><input type="hidden" name="action" value="setting"> <input class="bginput" type="submit" name="submit" value=" 提交 "> <input class="bginput" type="reset" name="Input" value=" 重置 "></td>
	</tr>
	</form>
</table>
</div>
</div>
<? include "footer.php";?><script type="text/javascript">
function msg(id,str){
	if( id=='error') return '<span class="error_msg">'+str+'</span>';
	if( id=='success') return '<span class="success_msg">'+str+'</span>';
}
function checkurl(id){
	var url=$('#'+id).val();
	if(url=='' || url.substr(0,7)!='http://' || url.substr(-1,1)!='/' ){
		$('#'+id+'_msg').html(msg('error','网址格式不正确！'));
	}else{
		$('#'+id+'_msg').html(msg('success','填写正确'));
	}
}
</script>

</body>
</html>
<?php
} elseif ($_GET ['id'] == 'save') {	
	$linkname = $_POST ['link_name'];
	$linkurl = $_POST ['link_url'];
	$linkorder = $_POST ['link_order'];
	$linkname_sub = ! empty ( $_POST ['link_name_sub'] ) ? trim ( $_POST ['link_name_sub'] ) : "";
	$linkurl_sub = ! empty ( $_POST ['link_url_sub'] ) ? trim ( $_POST ['link_url_sub'] ) : "";
	$linkorder_sub = ! empty ( $_POST ['link_order_sub'] ) ? trim ( $_POST ['link_order_sub'] ) : "";
	for($i = 0; $i < count ( $linkname ); $i ++) {
		if ($linkname [$i] != "") {
			$linkstr [$i] = $linkname [$i] . "|" . $linkurl [$i];
		}
	}
	if ($linkname_sub != "") {
		$linkstr [$linkorder_sub] = $linkname_sub . "|" . $linkurl_sub;
	}
	ksort ( $linkstr );
	while ( list ( $key, $value ) = each ( $linkstr ) ) {
		$linkstrs .= ";" . $value;
	}
	$word = '<?php' . "
	
	\r\n" . '$webtitle=' . '"' . $_POST ['webtitle'] . '"' . ";
	
	\r\n" . '$home_id=' . '"' . urlencode($_POST ['home_id']) . '"' . ";

	\r\n" . '$url=' . '"' . $_POST ['url'] . '"' . ";
	\r\n" . '$erji=' . '"' . $_POST ['erji'] . '"' . ";
	\r\n" . '$tongji=' . '"' . str_replace('"',"'",stripslashes($_POST ['tongji'])) . '"' . ";
	\r\n" . '$banquan=' . '"' . str_replace('"',"'",stripslashes($_POST ['banquan'])) . '"' . ";
	\r\n" . '$beian=' . '"' . $_POST ['beian'] . '"' . ";
	

	\r\n" . '$wyc=' . '"' . $_POST ['wyc'] . '"' . ";
	
	\r\n" . '$zhizhu=' . '"' . $_POST ['zhizhu'] . '"' . ";
	\r\n" . '$pinglun=' . '"' . $_POST ['pinglun'] . '"' .";
	\r\n". '$caiji=' . '"' . $_POST ['caiji'] . '"' . ";
	
	\r\n" . '$gjc=' . '"' . $_POST ['gjc'] . '"' . ";
	
	\r\n" . '$x_key=' . '"' . $_POST ['x_key'] . '"' . ";
	\r\n" . '$keywords=' . '"' . $_POST ['keywords'] . '"' . ";
	\r\n" . '$description=' . '"' . $_POST ['description'] . '"' . ";
	\r\n" . '$link=' . '"' . $linkstrs . '"' . ";
	\r\n" . '$conf=' . '"' . $_POST ['conf'] . '"' . ";
	\r\n" . '$appid=' . '"' . $_POST ['appid'] . '"' . ";
	\r\n" . '$template=' . '"' . $_POST ['template'] . '"' . ";
	\r\n?>";

	if (preg_match ( "/require|include|REQUEST|eval|system|fputs/i", $word )) {
		echo "<script>alert('含有非法字符！');location.href='?id=man';</script>";
		exit ();
	} else {
		$Dir = $_POST ['erji'];
		if ($Dir == "") {
			$Dir1 = "../";
		} else {
			$Dir1 = "../../";
		}
		$fp = fopen ( "../inc/config.php", "w" );
		fwrite ( $fp, $word );
		fclose ( $fp );
		
		echo "<script>alert('修改成功！');window.location='admin_main.php?id=man';</script>" ;;
		exit ();
	}
}
?>
