<?php 
//修改二级、三级页面顶部底部内部
require "../../Run.php";
require "../../include/getmkurl.fun.php";
$mkid = get_mkid("bbs/list.php");


   function class_id($cid){
	 if($cid <= 0){
	   $cid = 0;
	   }else{
	   $cid = $cid;
	       }
	   
	   return $cid;
	   }
	function add_info($cid){
	$wapid = WAPID;
	$sql = "SELECT cid,siteid FROM class_info WHERE cid='{$cid}' AND siteid='{$wapid}'";
	$result=mysql_query($sql);
	if($result && mysql_num_rows($result)>0){
	   $sql="UPDATE class_info SET top_two='{$_POST['top_two']}',bottom_two='{$_POST['bottom_two']}',top_three='{$_POST['top_three']}',bottom_three='{$_POST['bottom_three']}',listnums='{$_POST['listnums']}',password='{$_POST['password']}' WHERE cid='{$cid}' AND siteid='{$wapid}'";
       $result=mysql_query($sql);
	   if($result && mysql_affected_rows()>0){
			return '1';
       }else{
			return '0';
            }
	   }else{
	   $sql = 'INSERT INTO `class_info` (`iid`,`siteid`, `cid`, `list_style`, `view_style`, `top_two`, `top_three`, `bottom_two`, `bottom_three`, `listnums`, `password`) VALUES (NULL,\''.$wapid.'\', \''.$cid.'\', \''.$_POST['list_style'].'\', \''.$_POST['view_style'].'\', \''.$_POST['top_two'].'\', \''.$_POST['top_three'].'\', \''.$_POST['bottom_two'].'\', \''.$_POST['bottom_three'].'\', \''.$_POST['listnums'].'\', \''.$_POST['password'].'\');';
        $result = mysql_query($sql);
	   if($result && mysql_affected_rows()>0){
			return '1';
       }else{
			return '0';
            }	   
	   }
	}
	$cid = class_id($_GET['cid']);
    echo head('栏目广告内容').'<div class="title">栏目广告内容</div>';
	if($admin != 1 && $admin !=2){
	echo '<div class="tip">您好，您不具备相应的操作权限！</div>';
}else{
	if($_POST['mod'] == 'yes'){
	if($_POST['all'] == 'YES'||$_POST['all'] == 'yes'){
	    $sql="SELECT cid,cn,xuhao FROM class WHERE url='{$mkid}'";
        $result = mysql_query($sql);
        while(list($mclassid,$cn,$number) = mysql_fetch_row($result)){
	        add_info($mclassid);
	    }
		echo '<div class="tip">已经尝试应用于全部栏目</div>';
	}else{
	$mod = add_info($cid);
	   if($mod == '1'){
	    echo '<div class="tip">修改成功</div>';
		}else{
		 echo '<div class="tip">修改失败</div>';
		   }
	   }
	}
	echo '<div class="content">
	<form method="post" action="mod_ad.php?cid='.$_GET['cid'].'"> 二级栏目顶部内容<br> 
	<input type="text" name="top_two" value="'.class_get_info($cid,"top_two",$wapid).'">
	<br>二级栏目底部内容<br>
	<input type="text" name="bottom_two" value="'.class_get_info($cid,"bottom_two",$wapid).'">
	<br>三级栏目顶部内容<br>
	<input type="text" name="top_three" value="'.class_get_info($cid,"top_three",$wapid).'">
	<br>三级栏目底部内容<br>
	<input type="text" name="bottom_three" value="'.class_get_info($cid,"bottom_three",$wapid).'">
	<br>二级内容列表显示条数[留空或者非法值都将视为10；最大20]<br>
	<input type="text" name="listnums" value="'.class_get_info($cid,"listnums",$wapid).'">
	<br>栏目密码，不设请留空<br>
	<input type="text" name="password" value="'.class_get_info($cid,"password",$wapid).'">
	<input type="hidden" name="list_style" value="1">
	<input type="hidden" name="view_style" value="1">
	<br>是否应用于全部栏目（YES
	是，NO不是）<br>
	<input type="text" name="all" value="NO"><br>
	<input type="hidden" name="mod" value="yes">
	<input type="submit" value="保存修改"></form></div>';
	echo "<div class=\"mylink\"><a href=\"list.php?cid=".$_GET['cid']."\">返回上级</a><a href=\"../../index.php?\">网站首页</a></div></div>";
	}
	echo footer(1);
?>