<?php

/*

'**************************************************************************************************

' 软件名称: 黑色幻想舞曲管理系统CMS2.0

' 版本编号: hshxsdj 2.0

' 官方网站: http://www..hshxs.com

' 官方论坛：http://bbs.hshxs.com

' 版权所有: 黑色幻想开发团队    噬己翼(QQ:532917920)

' 郑重声明:

'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；

'    2、黑色幻想网络事业部保留此软件的法律追究权利

'**************************************************************************************************

*/

include "../include/conn.php";

include "../include/function.php";

include "admin_version.php";

include "admin_loginstate.php";

?>

<!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=gb2312" />

<title>广告管理</title>

<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>

<script src="js/jquery.js"></script>

<script src="js/alerts.js"></script>

<link href="images/alerts.css" rel="stylesheet" type="text/css" media="screen" />

<script language="javascript" src="js/html_js.js"></script>

<link  href="images/style.css" rel="stylesheet" type="text/css" />

<script language="javascript">

 $(document).ready(function(){



	$("#ChkAll").click(function(){

		if($(this).attr("checked")==true){

			$("input[id='S_ID']").each(function(){

				$(this).attr("checked",true);									 

			})							

		}else{

			$("input[id='S_ID']").each(function(){

				$(this).attr("checked",false);									 

			})							

		}

	})



	$("#addads").click(function(){

		 var S_Name=$("#S_Name").val();

		 var osource=$("#osource").val();

		 var S_GroupID=$("#S_GroupID").val();

		 $("#S_Name").css("border-color","#666 #ccc #ccc #666");

		 $("#sname").text("");

		 $("#osource1").text("");

		 $("#osource").css("border-color","#666 #ccc #ccc #666");

		 if (S_Name==""){

			 $("#S_Name").css("border","1px solid red");

			 $("#sname").text("请填写广告名称！").css("color","red");

			 return false;}

		 else if(S_Name.length > 50){

			 $("#sname").text("广告名不能超过50个字符！").css("color","red");

			 return false;}

		 else if (osource==""){

			 $("#osource").css("border","1px solid red");

			 $("#sname").text("请填写广告代码！").css("color","red");

			 return false;}



	})

	

	$("#btn_delall").click(function(){

		var page=$("#page").val();							

		jConfirm('确定要删除您所选中的广告吗?', '操作提示', function(r) {

				if(r==true){

					document.form1.action='?action=delall&Page='+page;

					form1.submit();}

				});

	 })



})

 

function del(id){

	jConfirm('您确定要删除该广告吗?', '操作提示', function(r) {

		if(r==true){

			window.location='?action=del&S_ID='+id;

			}

				});

		

		}



function spanjs(id){

	$.get('js/ajaxfun.php?action=spanjs&id='+id,function(R){

			if(R=="ok"){

				jPrompt('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>＊请将以上代码放置在你网站模板的对应位置！</font>','\<script src={chshdjcms:path}js/adjs/'+id+'.js\>\</script\>','广告js文件调用');

				}

		})

	}

	 

</script>

</head>



<body>

<?php

SystemPer(7);

	class ui_adsense{

		public function make($type){

			if($type==0){

				$names="缓冲广告";

				$filepath="../js/player/loading.html";

				}

			if(file_exists($filepath)){

				$filecontent=file_get_contents($filepath);	

				}

			else{

				$filecontent="文件不存在,加载内容失败!!";

				}	

				

?>

<form action="?action=savemake&types=<?php echo $type;?>" method="post">

<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">

    <tr>

        <td class="td_title">&nbsp;<?php echo $names;?>生成</td>

    </tr>

	<tr>

    	<td align="center">

        <textarea name="content" style="width:95%;font-family: Arial, Helvetica, sans-serif;font-size: 14px;" rows="25"><?php echo $filecontent;?></textarea>

        </td>

    </tr>

    <tr>

    	<td class="td_border" align="center">

        <input type="submit" value="确认编辑广告" class="rb1"/>

        &nbsp;&nbsp;&nbsp; 

        <input type="button" name="submit2" value="返回广告列表"  class="rb1" id="btn_add" onclick="window.location='admin_adsense.php';"/></td>

    </tr>

</table>

</form>



<?php			

			}

			

	public function showads($S_ID,$S_Name) {

?>

<div class="r_main">

	<div class="r_content">

		<div class="r_content_1">

	 <table width="100%"  border="0" cellpadding="0" cellspacing="0" class="tb_style">

          <tr>

            <td class="td_title" height="30" >&nbsp;<?php echo $S_Name?> &gt;&gt; 广告预览[<a onclick="javascript:history.back()" style="cursor:pointer;">返回</a>]</td>

          </tr>

          <tr>

          		<td><script language="javascript" src="../js/adjs/<?php echo $S_ID?>.js"></script></td>

          </tr>

          </table>

  		</div>

	</div>

</div>        

<?php			

			}

		

		public function editdata($Arr,$url){

			$name=$Arr[0];

			$group=$Arr[1];

			$html=$Arr[2];

			$use=$Arr[3];

			$js=$Arr[4];

			$fix=$Arr[5];

			

?>

<div class="r_main">

	<div class="r_content">

		<div class="r_content_1">

			<table width="100%"  border="0" cellpadding="0" cellspacing="0" class="tb_style">

			<form name="form" method="post" action="<?php echo $url?>" enctype="multipart/form-data">

			  <tr>

				<td height="30" colspan="2"  class="td_title">&nbsp;<?php echo $name?>广告管理</td>

			  </tr>

			  <tr>

				<td width="171"  height="30" align="right" class="td_border">广告名称：</td>

				<td width="580"  class="td_border"><input name="S_Name" type="text" id="S_Name" value="<?php echo $name?>" size="30" />

                    <font color="#FF0000">＊</font>				&nbsp; 广告分组：

				<select name="S_GroupID" id="S_GroupID">

                <option value="0">无广告组</option>

                <?php

				global $db;

				$sql="select * from s_adsgroup";

			  	$result=$db ->query($sql);

				if($result){

				  while($row=$db->fetch_array($result))

				  {

				?>

                	<option value="<?php echo $row['S_ID']?>" <?php if($row['S_ID']==$group){echo "selected";} ?>><?php echo $row['S_Name']?></option>

                <?php	  

					

				  }

				}

			?>

                </select>

                

                <label id="sname"></label></td>

			  </tr>

			  

			  

			  <tr>

				<td width="171" height="100" align="right" valign="middle"  class="td_border">&nbsp;广告代码<font color="red">(html)</font>：</td>

				<td class="td_border"><br />

				  <TEXTAREA  id="osource" name="S_TheAdrHtml" onKeyUp="change()" onFocus="change()" cols="70" rows="10" style="width:80%;font-family: Arial, Helvetica, sans-serif;font-size: 14px;" ><?php echo $html?></TEXTAREA>

                <font color="#FF0000">＊</font></td></tr>

             <tr>

             <td width="171" height="100" align="right" valign="middle"  class="td_border">&nbsp;广告代码<font color="red">(&nbsp;Js&nbsp;)</font>：</td>

               <td height="91" class="td_border"><br />

                 <TEXTAREA  id="oresult2" name="S_TheAdrJs" cols="70" rows="10" style="width:80%;font-family: Arial, Helvetica, sans-serif;font-size: 14px;" ><?php echo $js?></TEXTAREA>

               </td></tr> 

			  <tr>

				<td width="171" height="40" align="right"  class="td_border">&nbsp;开启状态：</td>

				<td class="td_border">

                	<input type="radio" name="S_IsUse" class="radio" id="S_IsUse" value="0" <?php if($use==0){echo "checked";}?> />开启&nbsp;&nbsp;&nbsp;&nbsp;

                    <input type="radio" name="S_IsUse" class="radio" id="S_IsUse" value="1" <?php if($use==1){echo "checked";}?> />关闭

                </td>

			  </tr>

			  <tr>

				<td width="171" height="30" class="td_border">&nbsp;</td>

				<td class="td_border"> &nbsp;

				  <input type="submit" name="Submit" value="确定提交" class="rb1" id="addads"/>

				  &nbsp;&nbsp; <input type="reset" name="Submit2" value="清除重置" class="rb1"/></td>

			  </tr>

			</form>  

		</table>

		</div>

	</div>

</div>

<?php			

			}

		public function main(){

			global $db;

			$Arr=getpagerow("select * from s_adsense",20);//sql,每页显示条数

			$result=$db->query($Arr[2]);

			$adnum=$db->num_rows($result);

?>

<div class="r_main">

	<div class="r_content">

		<div class="r_content_1">

          <form name="form1" action="?action=delall" method="post" id="form1">  

        <table width="100%"  border="0" cellpadding="0" cellspacing="0" class="tb_style">

          <tr>

            <td class="td_title" height="30" colspan="8">&nbsp;广告列表管理</td>

          </tr>





          <tr>

            <td width="64" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;编号</td>

            <td width="288" bgcolor="#FFFFFF" class="td_border">&nbsp;广告名称</td>



            <td width="124" align="center" bgcolor="#FFFFFF" class="td_border">所属分组</td>

            <td width="85" align="center" class="td_border">预览</td>

            <td width="140" align="center" bgcolor="#FFFFFF" class="td_border">增加时间</td>

             <td width="76" align="center" bgcolor="#FFFFFF" class="td_border">启用</td>

            <td align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;</td>

            <td align="center" bgcolor="#FFFFFF" class="td_border">操作选项</td>

          </tr>

            <tr>

          	<td width="64" height="30" align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;            </td>

            <td width="288" height="30" bgcolor="#FFFFFF" class="td_border">

            &nbsp;<strong><a href="?action=make&amp;types=0">播放前加载广告</a></strong></td>

            <td width="124" height="30" align="center" bgcolor="#FFFFFF" class="td_border">固定广告</td>

            <td width="85" height="30" align="center" bgcolor="#FFFFFF" class="td_border">

            <img src="images/zoom.jpg"  border="0"></td>

            <td width="140" height="30" align="center" bgcolor="#FFFFFF" class="td_border"><font color="#FF0000">2009-10-01</font></td>

            <td width="76" height="30" align="center" bgcolor="#FFFFFF" class="td_border">

            &nbsp;<img src="../images/common/yes.gif" border="0">            </td>

            <td width="98" height="30" align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;            </td>

            <td width="102" align="center" bgcolor="#FFFFFF" class="td_border"><a href="?action=make&amp;types=0">修改</a>&nbsp;&nbsp;删除</td>

          </tr>

				 <?php

				if($adnum==0) echo "

							<tr>

                            	<td colspan=\"8\" class=\"td_border\" height=\"30\" align=center><b>暂无广告,请添加！</b></td>

                            </tr>";				 

                 if($result){					 

                     while ($row = $db ->fetch_array($result)){



                 ?>   



                    <tr>

                      <td width="64" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;

                      <input type="checkbox" name="S_ID[]" value="<?php echo $row['S_ID']?>" class="checkbox" id="S_ID"/><?php echo $row['S_ID']?>、</td>

                      <td width="288" bgcolor="#FFFFFF" class="td_border"> &nbsp;<a href="?action=editdata&S_ID=<?php echo $row['S_ID']?>"><?php echo $row['S_Name']?></a></td>

                      <td width="124" align="center" bgcolor="#FFFFFF" class="td_border"><?php

                      	$sqlstr="select * from s_adsgroup where S_ID=".$row['S_GroupID']."";

						$rows=$db->getrow($sqlstr);

						if($rows){

							echo $rows['S_Name'];

							}

						else{

							echo "暂无分组";

							}

					  ?></td>

                      <td width="85" align="center" class="td_border"><a href="?action=showads&ids=<?php echo $row['S_ID']?>&names=<?php echo $row['S_Name']?>"><img src="images/zoom.jpg"  border="0"></a></td>

                      <td width="140" align="center" bgcolor="#FFFFFF" class="td_border"><font color="#FF0000"><?php echo $row['S_AddTime']?></font></td>

                      <td width="76" align="center" bgcolor="#FFFFFF" class="td_border"><a href="?action=isuse&S_ID=<?php echo $row['S_ID']?>&S_IsUse=<?php echo $row['S_IsUse']?>"><?php if($row['S_IsUse']==0){echo "<img src='../images/common/yes.gif'/>";}else{echo "<img src='../images/common/no.gif'/>";}?></a></td>

                      <td width="98"  align="center" bgcolor="#FFFFFF" class="td_border"><span style="color:red; cursor:pointer;" onclick="spanjs(<?php echo $row['S_ID']?>)"><strong>调用代码</strong></span></td>

                      <td width="102"  align="center" bgcolor="#FFFFFF" class="td_border"><a href="?action=editdata&amp;S_ID=<?php echo $row['S_ID']?>">修改</a>&nbsp;&nbsp;<a style="cursor:pointer;" onclick="del(<?php echo $row['S_ID']?>)">删除</a></td>

          </tr>

		   <?php

                                                               

                 }

             }

        ?> 

		<tr>

            <td width="64" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;<input type="hidden" name="page" id="page" value="<?php echo Page?>"><input type="checkbox" name="ChkAll" id="ChkAll" ids="S_ID"  class="checkbox"/>

            全选</td>

            <td height="30" colspan="7" bgcolor="#FFFFFF" class="td_border"> <input type="button" name="submit1" value="删除所选广告"  class="rb1" id="btn_delall"/>

              &nbsp; <input type="button" name="submit2" value="添加新广告"  class="rb1" id="btn_add" onclick="window.location='?action=add';"/></td>

          </tr>

          <tr>

            <td height="30" colspan="8" align="right" bgcolor="#FFFFFF" class="td_border"><?php echo $Arr[0];?></td>

          </tr>

        </table>

        </form>

		</div>

	</div>

</div>

<?php			

			

			}

		

		}

?>        



<?php

	$ui=new ui_adsense;

	$action=SafeRequest("action","get");

	switch ($action){

		case 'main':

			$ui->main();

			break;

		case 'editdata':

			editdata();

			break;

		case 'saveedit':

			saveedit();

			break;

		case 'add':

			add();

			break;

		case 'saveadd':

			saveadd();

			break;

		case 'del':

			del();

			break;

		case 'delall':

			delall();

			break;

		case 'showads':

			showads();

			break;

		case 'isuse':

			isuse();

			break;

		case 'make':

			make();

			break;

		case 'savemake':

			savemake();

			break;

		default:

			$ui->main();

		}

	function savemake(){

		global $db;

		$types=SafeRequest("types","get");

		$Content=stripslashes(SafeRequest("content","post"));

		if($types==0){

			$names=" 播放前加载广告";

			$filepath="../js/player/loading.html";

				}

		fwrite(fopen($filepath,"wb"),$Content);

		die("<script>jAlert('".$names."生成成功!','操作提示',function(R){window.location='admin_adsense.php'})</script>");

		}

		

	function make(){

		global $ui;

		$t=SafeRequest("types","get");

		$ui->make($t);

		}

		

	function isuse(){

		global $db;

		$isuse=SafeRequest("S_IsUse","get");

		$id=SafeRequest("S_ID","get");

		if(!IsNum($isuse)) $isuse=0;

		if(!IsNum($id)) die("<script>jAlert('id传输错误?','操作提示',function(R){history.back();})</script>");

		if($isuse==1){

			$isuse=0;

			}

		else{

			$isuse=1;

			}	

		$sql="update s_adsense set S_IsUse=$isuse where S_ID=$id";

		if($db->query($sql)){		

			die("<script>window.location='admin_adsense.php';</script>");

			}

		else{

			die("<script>jAlert('未知错误!','操作提示',function(R){history.back();})</script>");

			}		

		}

	

	function showads(){

		global $ui;

		$S_ID=SafeRequest("ids","get");

		$S_Name=SafeRequest("names","get");

		$ui->showads($S_ID,$S_Name);

		}

		

	function add(){

		global $ui;

		$Arr=array("","","","","",0);

		$ui->editdata($Arr,"?action=saveadd");

		}

		

	function saveadd(){

		global $db;

		$S_Name=SafeRequest("S_Name","post");

		$S_GroupID=SafeRequest("S_GroupID","post");

		$S_TheAdrHtml=SafeRequest("S_TheAdrHtml","post");

		$S_TheAdrJs=SafeRequest("S_TheAdrJs","post");

		$S_IsUse=SafeRequest("S_IsUse","post");

		$S_AddTime=date("Y-m-d");

		$sql="Insert s_adsense  (S_Name,S_GroupID,S_TheAdrHtml,S_TheAdrJs,S_IsUse,S_AddTime) values ('".$S_Name."',".$S_GroupID.",'".$S_TheAdrHtml."','".$S_TheAdrJs."',".$S_IsUse.",'".$S_AddTime."')";

		

		if($db->query($sql)){

			die("<script>window.location='admin_adsense.php';</script>");

			}

		else{

			die("<script>jAlert('添加广告失败！','操作提示',function(R){history.back();})</script>");

			}	

		

		}





	function delall(){

		global $db;

		$S_ID=RequestBox("S_ID");

		$sql="delete from s_adsense where S_ID in ($S_ID)";

		if($S_ID=="0"){

			die("<script>jAlert('请选择要删除的链接?','操作提示',function(R){history.back();})</script>");

			}

		else{

			if($db->query($sql)){

				die("<script>jAlert('恭喜你！操作成功了！','成功提示',function(R){window.location='admin_adsense.php';})</script>");

				}

			}	

		}



	function del(){

		global $db;

		$S_ID=SafeRequest("S_ID","get");

		$sql="delete from s_adsense where S_ID='".$S_ID."'";

		if($db->query($sql)){

			if(file_exists("../js/adjs/".$S_ID.".js")){

				unlink("../js/adjs/".$S_ID.".js");

				}

			echo "<script>window.location='admin_adsense.php';</script>";

			}

		}

	function saveedit(){

		global $db;

		$S_ID=SafeRequest("S_ID","get");

		$S_Name=SafeRequest("S_Name","post");

		$S_GroupID=SafeRequest("S_GroupID","post");

		$S_TheAdrHtml=SafeRequest("S_TheAdrHtml","post");

		$S_TheAdrJs=SafeRequest("S_TheAdrJs","post");

		$S_IsUse=SafeRequest("S_IsUse","post");

		$spanjscode=stripslashes($S_TheAdrJs);

		$sql="update s_adsense set S_Name='$S_Name',S_GroupID=$S_GroupID,S_TheAdrHtml='$S_TheAdrHtml',S_TheAdrJs='$S_TheAdrJs',S_IsUse=$S_IsUse where S_ID=$S_ID";



		if($db->query($sql)){

			

			fwrite(fopen("../js/adjs/".$S_ID.".js","wb"),$spanjscode);

			echo "<script>window.location='admin_adsense.php';</script>";

			}

		else{

			die("<script>jAlert('操作错误编辑失败!','操作提示',function(R){history.back();})</script>");

			}	

		

		}



	function editdata(){

		global $db;

		global $ui;

		$S_ID=SafeRequest("S_ID","get");

		if(IsNum($S_ID)){

			$sql="SELECT * FROM `s_adsense` Where S_ID='".$S_ID."'";

			$row=$db->Getrow($sql);

				if($row){

					$Arr=array($row['S_Name'],$row['S_GroupID'],$row['S_TheAdrHtml'],$row['S_IsUse'],$row['S_TheAdrJs'],$row['S_IsFix']);

					}

				$ui->editdata($Arr,"?action=saveedit&S_ID=".$S_ID."");

			}

		}



	

?>

<?php include "admin_bottom.php"; ?>

</body>

</html>