<? 
error_reporting ( 0 );
include('data.php');
if($_COOKIE['x_Cookie']!=$adminname and $_COOKIE['y_Cookie']!=$password){
	echo"<script>location.href='index.php';</script>";
	exit;
}

$edit = !empty( $_GET['e'] ) ? trim( $_GET['e'] ) : "";
$act = !empty( $_POST['action'] ) ? trim( $_POST['action'] ) : "";
$filen = !empty( $_POST['filename'] ) ? trim( $_POST['filename'] ) : "";
$contents = !empty( $_POST['content'] ) ? trim( $_POST['content'] ) : "";
$temp = "../ad/";
//记录时间
function filedate( $flietime ){    
$_flietime = date( "Y-m-d H:i:s", @filemtime( $flietime ) );    
return $_flietime;
}

?>
<!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>
<title>模板管理面版</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<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">
</head>
<body>
<?
if($_GET['id']=='ad'){
	?>
<div class="right">
   <? include_once "welcome.php";?>
  <div class="right_main">

      <table width="98%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <tr class="tb_head">
          <td colspan="5"><h2>广告管理：</h2></td>
        </tr>
        <tr align=center class="firstalt">
          <td width="30%" >文件名</td>
          <td width="30%" >文件描述</td>
          <td width="20%" nowrap>修改时间</td>
          <td width="20%" nowrap>操作</td>
        </tr>
        <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> top.js </td>
          <td >全局顶部广告</td>
          <td ><? echo filedate($temp."top.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=top.js">编辑</a></td>
        </tr>
        <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> footer.js</td>
          <td >全局弹窗或漂浮广告</td>
          <td ><? echo filedate($temp."footer.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=footer.js">编辑</a></td>
        </tr>
        <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> header.js</td>
          <td >全局导航栏下方广告</td>
          <td ><? echo filedate($temp."header.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=header.js">编辑</a></td>
        </tr>
		<tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> home.js</td>
          <td >首页中部广告</td>
          <td ><? echo filedate($temp."home.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=home.js">编辑</a></td>
        </tr>
        <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> list_ad1.js</td>
          <td >列表页列表上方广告</td>
          <td ><? echo filedate($temp."list_ad1.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=list_ad1.js">编辑</a></td>
        </tr>
                <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> view_ad1.js</td>
          <td >内容页问题下方广告</td>
          <td ><? echo filedate($temp."view_ad1.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=view_ad1.js">编辑</a></td>
        </tr>
		 <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> view_ad2.js</td>
          <td >最佳答案下方广告</td>
          <td ><? echo filedate($temp."view_ad2.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=view_ad2.js">编辑</a></td>
        </tr>
		<tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> view_ad3.js</td>
          <td >相关答案下方广告</td>
          <td ><? echo filedate($temp."view_ad3.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=view_ad3.js">编辑</a></td>
        </tr>
		<tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> view_right.js</td>
          <td >内容页右侧广告</td>
          <td ><? echo filedate($temp."view_right.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=view_right.js">编辑</a></td>
        </tr>
      </table>
<?
}elseif ($_GET['action']=='edit'){
    $filejs=fopen("../ad/".$_GET['e'],'a');
    fclose($filejs);
	$js1=file("../ad/".$_GET['e']);
	$js='';
	for($i=0;$i<count($js1);$i++){
		$js=$js.$js1[$i];
	}

?>
<table width="98%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
<tr><td>第1步：请将html源代码或待添加的广告代码拷贝到下面表单中: （只能在IE下运行，或者自行将HTML转换为JavaScript）<br>
<textarea style="width:98%;" cols="100" rows=8 id="oSource" onpropertychange="change()" ></textarea>
<br>
第2步：表单中是转换好的JS代码，直接复制到最下面的表单中即可(双击下面表单复制): <br />
<textarea style="width:98%;" cols="100" rows=8 id="oResult" title="双击复制" ondblclick='this.select();oResult.createTextRange().execCommand("Copy")'></textarea>
<br>

  <script>
 function change(){
 oResult.value="document.writeln(\""+oSource.value.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\'").split('\r\n').join("\");\ndocument.writeln(\"")+"\")"
 } </script></td></tr>
<form method="post" action="?action=add"><tr>
<th>将第2个的表单中的代码复制到这里-<? echo $_GET['e']; ?></th></tr>
<tr class="tb_head"><td colspan="2"><h2>模板编辑：<input name="filename" type="text" value="<? echo $edit; ?>">（不允许用 “..” 形式的路径）</h2></td></tr>
<tr><td width="98%"  height="100%"><input type="hidden" name="js_file" value="<? echo $_GET['e']; ?>" />
<textarea style="width:100%; height:100%;" rows="19" name="js_mb" cols="102"><? echo $js; ?></textarea></td></tr>
<tr><td  align="center"><input class="bginput" type="submit" name="submit" value=" 提交 " > <input class="bginput" type="reset" name="Input" value=" 重置 " ></td></tr>
</form>
</table>
<?
}elseif ($_GET['action']=="add"){
	//echo $_POST['js_mb'];
	$file="../ad/".$_POST['js_file'];
	$fp=fopen($file,"w");
	fwrite($fp,stripslashes($_POST['js_mb']));
	fclose($fp);
	echo"<script>alert('修改成功！');location.href='?id=ad';</script>";
}
?>
  </div>
</div>
<? include "footer.php"; ?>
</body>
</html>