<? 
//error_reporting ( 0 );
include('inc.php');
include('../inc/config.php');

$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 = "../templets/".$template."/ad/";
//记录时间
function filedate( $flietime ){    
$_flietime = date( "Y-m-d H:i:s", @filemtime( $flietime ) );    
return $_flietime;
}
function DeleteHtml($str) 
{ 

$str = ereg_replace("\t","",$str); 
$str = ereg_replace("\r\n","",$str); 
$str = ereg_replace("\r","",$str); 
$str = ereg_replace("\n","",$str); 

return trim($str); 
}

function htmltojs($s){
        $s=str_replace('"','\'',$s);
		
	    
		return $s;
		}
function jstohtml($s){
        $s=str_replace('\'','"',$s);
		$s=str_replace('document.writeln("','',$s);
		$s=str_replace('");','',$s);
		$s=str_replace('\/','/',$s);
		return $s;
		}
?><!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=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">
</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>PC端广告管理：</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"> <a href="?action=edit&e=header.js">header.js</a> </td>
          <td >全局顶部广告（html代码）</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"> <a href="?action=edit&e=index_right.js">index_right.js</a></td>
          <td >首页右侧广告（html代码）</td>
          <td ><? echo filedate($temp."index_right.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=index_right.js">编辑</a></td>
        </tr>
        <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> <a href="?action=edit&e=list_right.js">list_right.js</a></td>
          <td >列表页右侧广告（html代码）</td>
          <td ><? echo filedate($temp."list_right.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=list_right.js">编辑</a></td>
        </tr>
		<tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> <a href="?action=edit&e=a_top.js">a_top.js</a></td>
          <td >内容页文章顶部广告（html代码）</td>
          <td ><? echo filedate($temp."a_top.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=a_top.js">编辑</a></td>
        </tr>
        <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> <a href="?action=edit&e=a_foot.js">a_foot.js</a></td>
          <td >内容页文章底部广告（html代码）</td>
          <td ><? echo filedate($temp."a_foot.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=a_foot.js">编辑</a></td>
        </tr>
                <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> <a href="?action=edit&e=a_right.js">a_right.js</a></td>
          <td >内容页右侧广告（html代码）</td>
          <td ><? echo filedate($temp."a_right.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=a_right.js">编辑</a></td>
        </tr>
		 <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> <a href="?action=edit&e=a_right1.js">a_right1.js</a></td>
          <td >内容页右侧广告2（html代码）</td>
          <td ><? echo filedate($temp."a_right1.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=a_right1.js">编辑</a></td>
        </tr>
		
      </table><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"> <a href="?action=edit&e=mhtml.js">mhtml.js</a> </td>
          <td >内容页全局广告（html代码）</td>
          <td ><? echo filedate($temp."mhtml.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=mhtml.js">编辑</a></td>
        </tr>
        <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> <a href="?action=edit&e=m_top.js">m_top.js</a> </td>
          <td >内容页文章顶部广告（html代码）</td>
          <td ><? echo filedate($temp."m_top.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=m_top.js">编辑</a></td>
        </tr>
        <tr align=center class="firstalt">
          <td ><img src="img/top13.gif"> <a href="?action=edit&e=m_foot.js">m_foot.js</a> </td>
          <td >内容页文章底部广告（html代码）</td>
          <td ><? echo filedate($temp."m_foot.js");?></td>
          <td style="text-align:center"><a href="?action=edit&e=m_foot.js">编辑</a></td>
        </tr>
        
      </table>
<?
}elseif ($_GET['action']=='edit'){
    $filejs=fopen($temp.$_GET['e'],'a');
    fclose($filejs);
	$js1=file($temp.$_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">

<form method="post" action="?action=add">
<tr class="tb_head"><td colspan="3"><h2>广告编辑：<input name="filename" type="text" value="<? echo $edit; ?>">
  （不允许用 “..” 形式的路径）<b style=" color:#0033CC">【注意：    广告代码为HTML格式】</b></h2></td></tr>
<tr nowrap class="firstalt">
<td align="center" width="53%"  height="100%">
<textarea name="js_mb" cols="80" style="height: 150px; width: 100%"><?=jstohtml($js); ?></textarea> </td>
  <td width="5%"  align="center"><input class="bginput" type="submit" name="submit" value=" 提交 " > <input class="bginput" type="reset" name="Input" value=" 重置 " ></td>
  <td width="42%"  align="center"><b style=" color:rad">注意：    广告代码为HTML格式</b></td>
</tr>
</form>
</table> 
<?
}elseif ($_GET['action']=="add"){

	//echo $_POST['js_mb'];
	$file=$temp.$_POST['js_file'];
	$_POST['js_mb']=htmltojs(DeleteHtml($_POST['js_mb']));
	$_POST['js_mb']='document.writeln("'.$_POST['js_mb'].'");';
	$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>