<?php 
//修改二级、三级页面顶部底部内部

require "../../Run.php";
require "../../include/UBB.inc.php";
require "../../include/css.php";
function sitelink_info($id,$str){
      $sql="SELECT sitelinkid,{$str} FROM sitelink WHERE sitelinkid='{$id}'";
      $result = mysql_query($sql);
      if($result && mysql_num_rows($result)>0){
      list($sitelinkid,$str) = mysql_fetch_row($result);
      }else{
      $str="出错";
    }
	return $str;
}

  function lm_info($cid,$str,$wapid){
        $sql="SELECT cid,{$str} FROM class WHERE siteid='{$wapid}' AND cid='{$cid}'";
        $result=mysql_query($sql);
	    list($cid,$str) = mysql_fetch_row($result);
	    if($str == 'cn'){
	         if($cid==0||$cid==NULL||$cid==''){
	         $sql = "SELECT id,stitle FROM user WHERE id='{$wapid}'";
             $result = mysql_query($sql);
             list($wapid,$stitle) = mysql_fetch_row($result);
	         $str = $stitle;
             mysql_free_result($result);
	    }else{
	    $str = $str;
	       }
	   }else{
	   $str = $str;
	   }
	return $str;
	}

   function class_id($cid){
	 if($cid<=0){
	   if($_GET['id'] != NULL && $_GET['id']>0){
	   $cid = sitelink_info($_GET['id'],'gro');
	   }else{
	   $cid = 0;
	       }
	   }
	   return $cid;
	   }
	function mod_ad($str1,$str2,$str3,$str4,$str5,$str6){
	   $sql="UPDATE class SET two_t='{$str2}',two_b='{$str3}',three_t='{$str4}',three_b='{$str5}' WHERE cid='{$str1}' AND siteid='{$str6}'";
    $result=mysql_query($sql);
	if($result && mysql_affected_rows()>0){
	$tip=1;
    }else{
   $tip=0;
       }
	   return $tip;
	}
	$cid = class_id($_GET['cid']);
    echo head('栏目广告内容').'
	<body>'.$wap_top.'<div class="title">栏目广告内容</div>';
	if($_POST['mod']=='yes'){
	if($_POST['all']=='YES'||$_POST['all']=='yes'){
	    $sql="SELECT cid,cn,xuhao FROM class WHERE url='sitelink/list.php'";
        $result = mysql_query($sql);
        while(list($mclassid,$cn,$number) = mysql_fetch_row($result)){
	        $mod=mod_ad($mclassid,$_POST['two_t'],$_POST['two_b'],$_POST['three_t'],$_POST['three_b'],$wapid);
	    }
		echo '<div class="tip">已经尝试应用于全部栏目</div>';
	}else{
	$mod=mod_ad($_GET['cid'],$_POST['two_t'],$_POST['two_b'],$_POST['three_t'],$_POST['three_b'],$wapid);
	   if($mod==1){
	    echo '<div class="tip">修改成功</div>';
		}else{
		 echo '<div class="tip">修改失败</div>';
		   }
	   }
	}
	echo '<div class="content">
	<form method="post" enctype="multipart/form-data" action="mod_ad.php?cid='.$_GET['cid'].'&"> 二级栏目顶部内容<br> 
	<input type="text" name="two_t" value="'.lm_info($cid,"two_t",$wapid).'">
	<br>二级栏目底部内容<br>
	<input type="text" name="two_b" value="'.lm_info($cid,"two_b",$wapid).'">
	<br>三级栏目顶部内容<br>
	<input type="text" name="three_t" value="'.lm_info($cid,"three_t",$wapid).'">
	<br>三级栏目底部内容<br>
	<input type="text" name="three_b" value="'.lm_info($cid,"three_b",$wapid).'">
	<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']."&sid=".$sid_info."\">返回上级</a><a href=\"../../index.php?sid=".$sid_info."\">网站首页</a></div>";
	echo '</div>'.$wap_bottom.'
	</body></html>';
?>