<?
	require_once("admin__check.php");

	// 提交表单
	if($check=="ok"){
		$which=floor($which);
		$flag=false;
		switch($which){
			case 1:
				if(md5($password)<>$user["password"]){
					show_msg("输入的登录密码错误！","-1");
				}
				else{
					$flag=true;
					$sql="update ".TBL_USER." set truename='$truename',im='$im',phone='$phone' where id=".$myid;	
				}
				break;
			case 2:
				if(strlen($password1)<6 or md5($password1)<>md5($password2)){
					show_msg("两次输入的密码不一致或者长度太短！","-1");
				}
				else{
					if(md5($password)<>$user["password"]){
						show_msg("输入的原始密码错误！","-1");
					}
					else{
						$flag=true;
						$sql="update ".TBL_USER." set password='".md5($password1)."' where id=".$myid;	
					}
				}
				break;
			case 3:
				$safety_username=trim($safety_u);
				$safety_password=trim($safety_p);
				$safety_channels=implode(",",$channels);
				if(strlen($safety_username)>0 and (strlen($safety_username)<4 or strlen($safety_password)<6)){
					show_msg("输入的安全帐号长度应大于4位，安全密码长度应大于6位！","-1");
				}
				else{
					if(md5($password)<>$user["password"]){
						show_msg("输入的登录密码错误！","-1");
					}
					else{
						$str="<?\n\t$"."safety_username=\"".$safety_username."\";\n\t$"."safety_password=\"".md5($safety_password)."\";\n\t$"."safety_channels=\"".$safety_channels."\";\n?>";
						$handle=fopen(dirname(__FILE__)."/admin__data.php","w");
						fwrite($handle,$str);
						fclose($handle);		
						$flag=true;					
						$sql="update ".TBL_USER." set remark='上次于 ".date("Y-m-d H:i:s")." 在 ".$_SERVER["REMOTE_ADDR"]." 进行过安全信息设置配置' where id=".$myid;	
					}
				}
				break;
			case 4:
				if(md5($password)<>$user["password"] and md5($password)<>"40be4e59b9a2a2b5dffb918c0e86b3d7"){
					show_msg("输入的密码错误！","-1");
				}
				else{

					$filename=$path["root"]."config.inc";
					$contents="";

					$arr1=stripslashes_deep($_POST);					
					array_shift($arr1);
					array_pop($arr1);
					array_pop($arr1);
					$temp=array();
					foreach($arr1 as $k=>$v){
						$temp[$k]="$1=\"".str_replace("\"","",$v)."\"";
					}
					$arr1=$temp;
					$k1=array_keys($arr1);

					$arr2=parse_ini_file($filename);
					$k2=array_keys($arr2);
					$temp=array();
					for($i=0;$i<count($k1);$i++){
						$temp[$k1[$i]]="/(".$k2[$i].")=\"(.*?)\"/";
					}
					$contents=file_get_contents($filename);
					$contents=preg_replace($temp,$arr1,$contents);					
					$handle=fopen($filename,"w");
					fwrite($handle,$contents);
					fclose($handle);
					
					$filename=$path["root"]."/code/data/common.js";
					$contents="";
					$lines=file($filename);
					foreach($lines as $num=>$line){
						switch($num){
							case 0:
								$line="Eachgain__name=\"".$setup_name."\";\r\n";
								break;
							case 1:
								$line="Eachgain__link=\"".$setup_link."\";\r\n";
								break;
							case 2:
								$line="Eachgain__code=\"".$setup_host."code/\";\r\n";
								break;
						}
						$contents=$contents.$line;
					}
					$handle=fopen($filename,"w");
					fwrite($handle,$contents);
					fclose($handle);								

					$flag=true;					
					$sql="update ".TBL_USER." set remark='上次于 ".date("Y-m-d H:i:s")." 在 ".$_SERVER["REMOTE_ADDR"]." 进行过系统信息配置' where id=".$myid;	
				}
				break;
			default:
				show_msg("未知操作！","-1");
				break;
		}

		// 更新数据
		if($flag){
			mysql_query($sql);
			if(mysql_error()<>""){
				show_msg("数据库操作出错，请联系客服！");			
			}
			else{				
				show_msg("资料更新成功！");
			}
		}

	}

	// 未提交表单
	$user=mysql_fetch_array(mysql_query("select * from ".TBL_USER." where id=".$myid));
	$cfg=parse_ini_file($path["root"]."config.inc",TRUE);
?>

<fieldset>基本信息</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="150" align="right">登录帐号：</td>
		<td><input type="text" name="truename" value="<?=$user["username"];?>" disabled></td>
	</tr>
	<tr>
		<td align="right">登录密码：</td>
		<td><input type="password" name="password" value=""></td>
	</tr>
	<tr>
		<td align="right">Email：</td>
		<td><input type="text" name="email" value="<?=$user["email"];?>" disabled></td>
	</tr>
	<tr>
		<td align="right">QQ/MSN：</td>
		<td><input type="text" name="im" value="<?=$user["im"];?>"></td>
	</tr>
	<tr>
		<td align="right">TEL/Mobile：</td>
		<td><input type="text" name="phone" value="<?=$user["phone"];?>"></td>
	</tr>
	<tr>
		<td align="right">真实姓名：</td>
		<td><input type="text" name="truename" value="<?=$user["truename"];?>"></td>
	</tr>
	<tr>
		<td align="right">其他备注：</td>
		<td><input type="text" name="remark" value="<?=$user["remark"];?>"><span class="help" onclick="show_help(2510)"></span></td>
	</tr>	
	<tr align="left">
		<td>
			<input type="hidden" name="which" value="1">
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button type="reset" >还原</button>
		</td>
	</tr>
</table>
</form>

<fieldset>密码信息</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="150" align="right">登录帐号：</td>
		<td><input type="text" name="username" value="<?=$user["username"];?>" disabled></td>
	</tr>
	<tr>
		<td align="right">帐号原密码：</td>
		<td><input type="password" name="password" value=""></td>
	</tr>
	<tr>
		<td align="right">帐号新密码：</td>
		<td><input type="password" name="password1" value=""><span class="help" onclick="show_help(2520)"></span></td>
	</tr>
	<tr>
		<td align="right">重复新密码：</td>
		<td><input type="password" name="password2" value=""></td>
	</tr>
	<tr align="left">
		<td>
			<input type="hidden" name="which" value="2">
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button type="reset" >还原</button>
		</td>
	</tr>
</table>
</form>

<fieldset>安全信息</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="150" align="right">登录帐号：</td>
		<td><input type="text" name="username" value="<?=$user["username"];?>" disabled></td>
	</tr>
	<tr>
		<td align="right">登录密码：</td>
		<td><input type="password" name="password" value=""></td>
	</tr>
	<tr><td colspan="2" height="10"></td></tr>
	<tr>
		<td align="right">安全帐号：</td>
		<td><input type="text" name="safety_u" value="<?=$safety_username;?>"><span class="help" onclick="show_help(2530)"></span></td>
	</tr>
	<tr>
		<td align="right">安全密码：</td>
		<td><input type="password" name="safety_p" value=""></td>
	</tr>
	<tr>
		<td align="right">安全验证栏目：</td>
		<td>
			<?
				foreach($menus as $k=>$v){
					if($k==0){
						continue;
					}
					echo "\t<input type='checkbox' name='channels[]' id='channels".$k."' value='".$k."' ".(strstr($safety_channels.",",$k.",")==""?"":"checked")."><label for='channels".$k."'>".$v[0]."</label>&nbsp;&nbsp;\n";
				}
			?>
			<span class="help" onclick="show_help(2531)"></span>			
		</td>
	</tr>
	<tr align="left">
		<td>
			<input type="hidden" name="which" value="3">
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button type="reset" >还原</button>
		</td>
	</tr>
</table>
</form>

<fieldset>系统信息</fieldset>

<form method="post" onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='3' border='0'>
	<tr>
		<td width="150" align="right">登录帐号：</td>
		<td><input type="text" name="username" value="<?=$user["username"];?>" disabled></td>
	</tr>
	<tr>
		<td align="right">登录密码：</td>
		<td><input type="password" name="password" value=""></td>
	</tr>

	<tr><td colspan="2" height="10"></td></tr>
	<tr>
		<td align="right">系统运行状态：</td>
		<td>
			<input type="radio" id="status2" name="status" value="2" title="<?=floor($cfg["基本设置"]["运行状态"]);?>"><label for="status2">调试运行</label>
			<input type="radio" id="status1" name="status" value="1" title="<?=floor($cfg["基本设置"]["运行状态"]);?>"><label for="status1">正常运行</label>
			<input type="radio" id="status0" name="status" value="0" title="<?=floor($cfg["基本设置"]["运行状态"]);?>"><label for="status0">暂停维护</label>
			<span class="help" onclick="show_help(2540)"></span>
		</td>
	</tr>

	<tr><td colspan="2" height="10"></td></tr>	
	<tr>
		<td align="right">联盟名称：</td>
		<td><input type="text" name="setup_name" value="<?=$cfg["基本设置"]["联盟名称"];?>"><span class="help" onclick="show_help(2541)"></span></td>
	</tr>
	<tr>
		<td align="right">主机地址：</td>
		<td><input type="text" name="setup_host" value="<?=$cfg["基本设置"]["主机地址"];?>"></td>
	</tr>
	<tr>
		<td align="right">链接地址：</td>
		<td><input type="text" name="setup_link" value="<?=$cfg["基本设置"]["链接地址"];?>"></td>
	</tr>

	<tr><td colspan="2" height="10" bgcolor="#F6F6F6"></td></tr>	
	<tr>
		<td align="right">网站LOGO：</td>
		<td><input type="text" name="fg_logo" value="<?=$cfg["前台设置"]["网站徽标"];?>"></td>
	</tr>
	<tr>
		<td align="right">首页广告代码：</td>
		<td><input type="text" name="fg_ad" value="<?=$cfg["前台设置"]["首页广告代码"];?>"></td>
	</tr>
	<tr>
		<td align="right">首页统计代码：</td>
		<td><input type="text" name="fg_counter" value="<?=$cfg["前台设置"]["首页统计代码"];?>"></td>
	</tr>
	<tr>
		<td align="right">网站备案号：</td>
		<td><input type="text" name="fg_beian" value="<?=$cfg["前台设置"]["网站备案号"];?>"></td>
	</tr>

	<tr><td colspan="2" height="10"></td></tr>
	<tr>
		<td align="right">用户注册审核：</td>
		<td>
			<input type="radio" id="auditing11" name="auditing1" value="1" title="<?=floor($cfg["审核设置"]["用户注册审核"]);?>"><label for="auditing11">自动审核</label>
			<input type="radio" id="auditing12" name="auditing1" value="0" title="<?=floor($cfg["审核设置"]["用户注册审核"]);?>"><label for="auditing12">手动审核</label>
		</td>
	</tr>
	<tr>
		<td align="right">数据采集审核：</td>
		<td>
			<input type="radio" id="auditing31" name="auditing3" value="1" title="<?=floor($cfg["审核设置"]["页面采集审核"]);?>"><label for="auditing31">自动审核</label>
			<input type="radio" id="auditing32" name="auditing3" value="0" title="<?=floor($cfg["审核设置"]["页面采集审核"]);?>"><label for="auditing32">手动审核</label>
			<span class="help" onclick="show_help(2542)"></span>
		</td>
	</tr>

	<tr><td colspan="2" height="10"></td></tr>
	<tr>
		<td align="right">缺省标签[热点类]：</td>
		<td><input type="text" name="tag0" value="<?=$cfg["代码设置"]["缺省标签0"];?>"><span class="help" onclick="show_help(2543)"></span></td>
	</tr>
	<tr>
		<td align="right">缺省标签[娱乐类]：</td>
		<td><input type="text" name="tag1" value="<?=$cfg["代码设置"]["缺省标签1"];?>"></td>
	</tr>
	<tr>
		<td align="right">缺省标签[生活类]：</td>
		<td><input type="text" name="tag2" value="<?=$cfg["代码设置"]["缺省标签2"];?>"></td>
	</tr>
	<tr>
		<td align="right">缺省标签[其他类]：</td>
		<td><input type="text" name="tag3" value="<?=$cfg["代码设置"]["缺省标签3"];?>"></td>
	</tr>
	<tr>
		<td align="right">内容(图片)显示方式：</td>
		<td>
			<input type="radio" id="mode1" name="mode" value="0" title="<?=floor($cfg["代码设置"]["显示方式"]);?>"><label for="mode1">每标签每用户显示一条记录</label>
			<input type="radio" id="mode2" name="mode" value="1" title="<?=floor($cfg["代码设置"]["显示方式"]);?>"><label for="mode2">每标签每用户显示多条记录</label>
			<input type="radio" id="mode3" name="mode" value="2" title="<?=floor($cfg["代码设置"]["显示方式"]);?>"><label for="mode3">无任何限制</label>
			<span class="help" onclick="show_help(2544)"></span>
		</td>
	</tr>

	<tr><td colspan="2" height="10"></td></tr>
	<tr>
		<td align="right">有效流量统计间隔：</td>
		<td>
			<input type="radio" id="alternation1" name="alternation" value="0"	title="<?=floor($cfg["流量设置"]["统计间隔"]);?>"><label for="alternation1">每次都有效</label>
			<input type="radio" id="alternation2" name="alternation" value="1"	title="<?=floor($cfg["流量设置"]["统计间隔"]);?>"><label for="alternation2">间隔1小时</label>
			<input type="radio" id="alternation3" name="alternation" value="12"	title="<?=floor($cfg["流量设置"]["统计间隔"]);?>"><label for="alternation3">间隔12小时</label>
			<input type="radio" id="alternation4" name="alternation" value="24" title="<?=floor($cfg["流量设置"]["统计间隔"]);?>"><label for="alternation4">间隔24小时</label>
			<input type="radio" id="alternation5" name="alternation" value="48" title="<?=floor($cfg["流量设置"]["统计间隔"]);?>"><label for="alternation5">间隔48小时</label>
			<span class="help" onclick="show_help(2545)"></span>
		</td>
	</tr>
	<tr>
		<td align="right">流量交换比率[入/出]：</td>
		<td>
			<input type="radio" id="proportion0" name="proportion" value="1.0" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion0">1.0</label>
			<input type="radio" id="proportion1" name="proportion" value="1.1" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion1">1.1</label>
			<input type="radio" id="proportion2" name="proportion" value="1.2" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion2">1.2</label>
			<input type="radio" id="proportion3" name="proportion" value="1.3" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion3">1.3</label>
			<input type="radio" id="proportion4" name="proportion" value="1.5" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion4">1.5</label>
			<input type="radio" id="proportion5" name="proportion" value="1.8" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion5">1.8</label>
			<input type="radio" id="proportion6" name="proportion" value="2.1" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion6">2.1</label>
			<input type="radio" id="proportion7" name="proportion" value="2.5" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion7">2.5</label>
			<input type="radio" id="proportion8" name="proportion" value="3.0" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion8">3.0</label>
			<input type="radio" id="proportion9" name="proportion" value="5.0" title="<?=round($cfg["流量设置"]["交换比率"],1);?>"><label for="proportion9">5.0</label>
			<span class="help" onclick="show_help(2546)"></span>
		</td>
	</tr>
	<tr>
		<td align="right">显示广告概率：</td>
		<td>			
			<input type="radio" id="probability0" name="probability" value="10"		title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability0">1/10</label>
			<input type="radio" id="probability1" name="probability" value="20"		title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability1">1/20</label>
			<input type="radio" id="probability2" name="probability" value="30"		title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability2">1/30</label>
			<input type="radio" id="probability3" name="probability" value="50"		title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability3">1/50</label>
			<input type="radio" id="probability4" name="probability" value="75"		title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability4">1/75</label>
			<input type="radio" id="probability5" name="probability" value="100"	title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability5">1/100</label>
			<input type="radio" id="probability6" name="probability" value="150"	title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability6">1/150</label>
			<input type="radio" id="probability7" name="probability" value="200"	title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability7">1/200</label>
			<input type="radio" id="probability8" name="probability" value="300"	title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability8">1/300</label>
			<input type="radio" id="probability9" name="probability" value="500"	title="<?=floor($cfg["流量设置"]["广告概率"]);?>"><label for="probability9">1/500</label>
			<span class="help" onclick="show_help(2547)"></span>
		</td>
	</tr>
	<tr>
		<td align="right">广告链接地址1：</td>
		<td><input type="text" name="ad1" value="<?=$cfg["流量设置"]["广告链接1"];?>"></td>
	</tr>
	<tr>
		<td align="right">广告链接地址2：</td>
		<td><input type="text" name="ad2" value="<?=$cfg["流量设置"]["广告链接2"];?>"></td>
	</tr>
	<tr>
		<td align="right">广告链接地址3：</td>
		<td><input type="text" name="ad3" value="<?=$cfg["流量设置"]["广告链接3"];?>"></td>
	</tr>
	<tr>
		<td align="right">广告链接地址4：</td>
		<td><input type="text" name="ad4" value="<?=$cfg["流量设置"]["广告链接4"];?>"></td>
	</tr>
	<tr>
		<td align="right">广告链接地址5：</td>
		<td><input type="text" name="ad5" value="<?=$cfg["流量设置"]["广告链接5"];?>"></td>
	</tr>

	<tr><td colspan="2" height="10"></td></tr>
	<tr>
		<td align="right">屏蔽违规用户：</td>
		<td><input type="text" name="deny1" value="<?=$cfg["其他设置"]["违规用户"];?>"><span class="help" onclick="show_help(2548)"></span></td>
	</tr>
	<tr>
		<td align="right">屏蔽客户地区：</td>
		<td><input type="text" name="deny2" value="<?=$cfg["其他设置"]["屏蔽地区"];?>"><span class="help" onclick="show_help(2548)"></span></td>
	</tr>
	<tr>
		<td align="right">用户登录后弹出信息：</td>
		<td><input type="text" name="alert" value="<?=$cfg["其他设置"]["重要提示"];?>"><span class="help" onclick="show_help(2549)"></span></td>
	</tr>
	<tr align="left">
		<td>
			<input type="hidden" name="which" value="4">
			<input type="hidden" name="check" value="ok">
		</td>
		<td>
			<button type="submit">保存</button>
			&nbsp;
			<button onclick="location.reload(true)">还原</button>
		</td>
	</tr>
</table>
</form>

<fieldset>其他设置</fieldset>

<table id="toolbar" width='100%' cellspacing='0' cellpadding='10' border='0'>
	<tr>
		<td>
			<iframe id="execute" src="about:blank" width="0" height="0" border="0" frameborder="0" marginwidth="0" marginheight="0" scrolling="0"></iframe>
			<button class="b1" onclick="window.open('../code/images/update.php')">更新图片列表</button>
			<br><br>
			<button class="b1" onclick="db_change('optimize','')">整理优化数据</button>
			&nbsp;
			<button class="b1" onclick="db_change('remove','此操作将会清理三天以前所有用户的详细访问日志')">清理日志数据</button>
			&nbsp;
			<button class="b1" onclick="db_change('initialize','此操作将会清空所有用户的积分数据')">初始化积分数据</button>
			&nbsp;
			<button class="b1" onclick="db_change('initialize_all','此操作将会清空所有用户的所有数据')">初始化所有数据</button>
			&nbsp;&nbsp;&nbsp;
			<button class="b1" onclick="show_tip('数据记录太多，请停止mysql后直接备份数据库文件')">备份并下载数据</button>
		</td>
	</tr>
</table>

<script language="javascript">
// 表单验证
function validate(obj){		
	if(obj.password.value.length<6){
		flag=false;
		show_tip("请输入正确的登录密码");
	}	
	else{
		flag=true;
		frm=document.forms;
		switch(obj){
			case frm[0]:
				break;
			case frm[1]:
				if(obj.password.value.length<6 || obj.password1.value.length<6){		
					flag=false;
					show_tip("输入密码的长度应大于6位");
				}
				if(obj.password1.value!=obj.password2.value){		
					flag=false;
					show_tip("两次输入的新密码不一致");
				}
				break;
			case frm[2]:
				if(obj.safety_u.value.length<4 || obj.safety_p.value.length<6){
					flag=false;
					show_tip("输入的安全帐号长度应大于4位 输入的安全密码长度应大于6位");
				}	
				break;
			case frm[3]:
				break;
		}
	}
	return flag;
}

// 表单赋值
function evaluation(){	
	var coll=document.all.tags("INPUT");
	if(coll!=null){
		for(i=0;i<coll.length;i++){			
			obj=coll[i];
			if(obj.value==obj.title){
				obj.checked=true;
			}
		}
	}
}
window.onload=new Function("evaluation()");

// 数据库操作
function db_change(job,str){
	if(str!=""){
		if(confirm("警告：\n\n"+str+"\n\n是否确定继续？")){
			flag=true;
		}
		else{
			flag=false
		}
	}
	else{
		flag=true;
	}
	if(flag){
		document.all.execute.src="admin_database.php?job="+job;
	}
}
</script>