<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "admin_loginstate.php";
include "../include/conn.php";
include "../include/function.php";
include "admin_version.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 language="javascript" src="js/jquery.js"></script>
<script src="js/alerts.js"></script>
<link href="images/alerts.css" rel="stylesheet" type="text/css" media="screen" />
<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);									 
			})							
		}
	})
	$("#addadsg").click(function(){
		 var S_Name=$("#S_Name").val();
		 var S_Remark=$("#S_Remark").val();
		 $("#S_Name").css("border-color","#666 #ccc #ccc #666");
		 $("#sname").text("");		 
		 $("#S_Remark").css("border-color","#666 #ccc #ccc #666");
		 $("#SRemark").text("");
		 if (S_Name==""){
			 $("#S_Name").css("border","1px solid red");
			 $("#sname").text("请填写广告组名！")
			 $("#sname").css("color","red");
			 return false;}
		 else if(S_Name.length > 50){
			 $("#S_Name").css("border","1px solid red");
			 $("#sname").text("广告名不能超过50个字符！")
			 $("#sname").css("color","red");
			 return false;}
		else if(S_Remark==""){
			 $("#S_Remark").css("border","1px solid red");
			 $("#SRemark").text("请填写广告组描述！")
			 $("#SRemark").css("color","red");
			 return false;}
		else if(S_Remark.length > 100){
			 $("#S_Remark").css("border","1px solid red");
			 $("#SRemark").text("广告组描述不能超过100个字符！")
			 $("#SRemark").css("color","red");
			 return false;}
		})
	
	$("#btn_delall").click(function(){
		jConfirm('您确定要删除选中的广告吗?', '操作提示', function(r) {
				if(r==true){
					form1.submit();}
				});
	 })
})
function del(id){
	jConfirm('您确定要删除选中的广告吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
		
		}
</script>

</head>

<body>
<?php
	class ui_adsgroup{
		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>][<a href="?action=showads&ids=<?php echo $S_ID?>&names=<?php echo $S_Name?>">刷新</a>]</td>
          </tr>
          <tr>
          		<td><script language="javascript" src="../js/adshow.php?types=1&adid=<?php echo $S_ID?>"></script></td>
          </tr>
          </table>
  		</div>
	</div>
</div>        
<?php			
			}		
		public function editdata($Arr,$url){
				$name=$Arr[0];
				$remark=$Arr[1];
				$use=$Arr[2];
?>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
  <form id="form" name="form" method="post" action="<?php echo $url?>">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tb_style" w>
          <tr>
 <td height="30" colspan="2"  bgcolor="#FFFFFF" class="td_title"><strong>&nbsp;<?php echo $name?>广告组</strong></td>
          </tr>
		  <tr>
            <td width="251" height="40" align="right" bgcolor="#FFFFFF" class="td_border">广告组名称：</td>
            <td height="30" align="left" bgcolor="#FFFFFF" class="td_border"><input name="S_Name" type="text" id="S_Name" value="<?php echo $name?>" size="38" />
            &nbsp;<font color="#FF0000">＊</font>
            <label id="sname"></label></td>
		  </tr>
		  <tr>
		    <td width="251" height="30" align="right" bgcolor="#FFFFFF" class="td_border">广告组描述：</td>
		    <td height="30" align="left" bgcolor="#FFFFFF" class="td_border"><textarea name="S_Remark" cols="32" rows="3" id="S_Remark"><?php echo $remark?></textarea>
	            <font color="#FF0000">＊
	            <label id="SRemark"></label>
            </font></td>
	      </tr>
		  <tr>
		    <td width="251" height="40" align="right" bgcolor="#FFFFFF" class="td_border">广告组状态：</td>
		    <td height="30" align="left" bgcolor="#FFFFFF" class="td_border"><input type="radio" name="S_IsUse" class="radio"  value="0"  <?php if($use==0){echo "checked";} ?>/>
开启&nbsp;
<input type="radio" class="radio" name="S_IsUse" value="1" <?php if($use==1){echo "checked";} ?>/>
关闭 </td>
	      </tr>
		  <tr>
		    <td height="40" align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;</td>
		    <td height="30" align="left" bgcolor="#FFFFFF" class="td_border"><input type="submit" name="button" id="addadsg" value="确认提交" class="rb1" />
		    &nbsp;&nbsp; <input name="Submit" type="reset" class="rb1" id="Submit" value="清除重置"/></td>
	      </tr>
    </table>
</form>
		</div>
	</div>
</div>
<?php			
			}
		
		public function main(){
			global $db;
			$Arr=getpagerow("select * from s_adsgroup",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 height="30" colspan="6"  bgcolor="#FFFFFF" class="td_title"><strong>&nbsp;广告组列表</strong></td>
            </tr>
            <tr>
              <td width="11%"  height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;编号</td>
              <td width="19%"  bgcolor="#FFFFFF" class="td_border">&nbsp;广告组名</td>
              <td width="24%" bgcolor="#FFFFFF" class="td_border">&nbsp; 广告组描述</td>
              <td width="4%" align="center"  bgcolor="#FFFFFF" class="td_border">预览</td>              
              <td width="20%"  align="center" bgcolor="#FFFFFF" class="td_border">启用</td>
              <td width="22%"  height="30" align="center" bgcolor="#FFFFFF" class="td_border">操作选项</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 height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&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  height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;<a href="admin_Adsense.ASP?S_ID=<?php echo $row["S_ID"]?>&action=listbycls"><?php echo $row["S_Name"]?></a></td>
              <td  bgcolor="#FFFFFF" class="td_border">&nbsp; <?php echo $row['S_Remark']?></td>
              <td 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  align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<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  align="center" bgcolor="#FFFFFF" class="td_border"><a href='#' onclick="jPrompt('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>＊请将以上代码放置在你网站模板的对应位置！</font>','<script src={syccms:path}js/adshow.php?types=1&adid=<?php echo $row['S_ID']?>></script>','<?php echo $row["S_Name"]?>')"><strong><font color="#FF0000">调用代码</font></strong></a>&nbsp;&nbsp;
<a href="?action=editdata&S_ID=<?php echo $row["S_ID"]?>">修改</a>&nbsp; <a href="#"  onclick="del(<?php echo $row["S_ID"]?>)">删除</a></td>
            </tr>
		   <?php
                                                               
                 }
             }
        ?> 
			<tr>
              <td height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;<input type="checkbox" name="ChkAll" class="checkbox" id="ChkAll"/>
全选&nbsp;&nbsp;</td>
              <td height="30" colspan="5" bgcolor="#FFFFFF" class="td_border"><input type="button" name="submit1" value="删除所选分组"  class="rb1" id="btn_delall" />
              &nbsp; <input type="button" name="submit1" value="添加广告组"  class="rb1" id="btn_add" onclick="window.location='?action=add';"/></td>
            </tr>
			            <tr>
			              <td height="30" colspan="6" bgcolor="#FFFFFF" class="td_border" align="right">&nbsp;<?php echo $Arr[0];?></td>
          </tr>
          </table>
        </form>
		</div>
	</div>
</div>
<?php			
			
			}		
		
		}//end class

?>
        

<?php
	$ui=new ui_adsgroup;
	$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;
		default:
			$ui->main();
		}
	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_adsgroup set S_IsUse=$isuse where S_ID=$id";
		if($db->query($sql)){
			die("<script>window.location='admin_adsgroup.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_Remark=SafeRequest("S_Remark","post");
		$S_IsUse=SafeRequest("S_IsUse","post");
		$sql="Insert s_adsgroup  (S_Name,S_Remark,S_IsUse) values ('".$S_Name."','".$S_Remark."',".$S_IsUse.")";
		$db->query($sql);
		echo "<script>window.location='admin_AdsGroup.php';</script>";
		}


	function delall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		$sql="delete from s_adsgroup 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_AdsGroup.php';})</script>");
				}
			}	
		}

	function del(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$sql="delete from s_adsgroup where S_ID='".$S_ID."'";
		if($db->query($sql)){
			echo "<script>window.location='admin_AdsGroup.php';</script>";
			}
		}


	function saveedit(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$S_Name=SafeRequest("S_Name","post");
		$S_Remark=SafeRequest("S_Remark","post");
		$S_IsUse=SafeRequest("S_IsUse","post");
		$sql="update s_adsgroup set S_Name='".$S_Name."',S_Remark='".$S_Remark."',S_IsUse=".$S_IsUse." where S_ID=".$S_ID."";
		$db->query($sql);
		echo "<script>window.location='admin_AdsGroup.php';</script>";
		}

	function editdata(){
		global $db;
		global $ui;
		$S_ID=SafeRequest("S_ID","get");
		if(IsNum($S_ID)){
			$sql="SELECT * FROM `s_adsgroup` Where S_ID='".$S_ID."'";
			$row=$db->Getrow($sql);
				if($row){
					$Arr=array($row['S_Name'],$row['S_Remark'],$row['S_IsUse']);
					}
				$ui->editdata($Arr,"?action=saveedit&S_ID=".$S_ID."");
			}
		}

	
?>
<?php include "admin_bottom.php"; ?>
</body>
</html>