<?php 
////////////////////////////////////////////////
////css切换      独立开发      版权所有     ////
////////////////////////////////////////////////

require "Run.php";

if($_GET['action'] == 'admin'){
//管理页面
if($admin==1||$admin==2 ){
  if($_GET['type'] == 'yes'){
         $sql    =  "SELECT cssid,csscn,csscontent,color,site FROM css WHERE site='{$wapid}'";  
         $result =  mysql_query($sql);      
	     if($result && mysql_num_rows($result) > 0){
	     $i      =  0;
	     while(list($css_id,$css_cn,$css_content,$color,$site) = mysql_fetch_row($result)){
		    if($css_id == $_GET['id']){
			    $ifmr  = '1';
				 }else{
				 $ifmr = '0';
				 }
			mysql_query("UPDATE css SET mr='{$ifmr}' WHERE cssid='{$css_id}'");
			}
		
			}else{
			die('程序出现逻辑错误，请联系系统管理员！');
			}
		 	header("location: CssSelect.php?action=admin");
	}elseif($_GET['type'] == 'del'){
		$sql = "DELETE FROM css WHERE cssid='{$_GET[id]}' AND site ='{$wapid}'";
		$result = mysql_query($sql);
		if($result && mysql_affected_rows()>0){
				header("location: CssSelect.php?action=admin");
		}else{
				header("location: CssSelect.php?action=admin");
		}
   }else{
   $sql="SELECT cssid,csscn,csscontent,color,site,mr FROM css WHERE site='{$wapid}' ORDER BY cssid DESC";  
    $result = mysql_query($sql);      
	if($result && mysql_num_rows($result) > 0){
	$i=0;
	while(list($css_id,$css_cn,$css_content,$color,$site,$ifmrc) = mysql_fetch_row($result)){
	      if($ifmrc == '1'){
		     $text = '<img src="http://'.$_SERVER['HTTP_HOST'].'/style/right.gif"/>';
			 }else{
			 $text = '';
			 }
	$div = $num++%2 == 0?'line1':'line2';
	$html.= '<div class="'.$div.'"><font color="'.$color.'">[<a href="CssSelect.php?action=admin&type=yes&id='.$css_id.'">默认</a>|<a href="CssSelect.php?action=admin&type=del&id='.$css_id.'">删除</a>|
	<a href="CssSelect.php?action=view&id='.$css_id.'">修改</a>]
	<a href="CssSelect.php?action=view&id='.$css_id.'&sid='.$userinfo['sid'].'-'.$userinfo['ver'].'-'.$cssid.'" >'.$css_cn.'</a>'.$text.'</font></div>';
	 }
	 }else{
	 $html = '<div class="content">此栏目暂无记录!请联系管理员添加！</div>';
	 }
     mysql_free_result($result);
     $html = '<div class="title">
	 <a href="CssSelect.php?action=add&">添加CSS样式</a>
	 </div>'.$html.'<div class="mylink"><a href="admin/wap_admin.php?">管理后台</a>|<a href="index.php?">网站首页</a></div>';
         }
    }else{
	echo '您好，您无权进入此页面！';
	}
  }elseif($_GET['action'] == 'view'){
  if($admin == 1 || $admin == 2){
     if($_POST['type'] == 'mod'){
	       //执行修改 
		   $content = $_POST['csscontent']; 
	       $sql="UPDATE css SET csscn='{$_POST['csscn']}',color='{$_POST['color']}',csscontent='{$content}',ver='{$_POST['ver']}' WHERE cssid='{$_GET['id']}' AND site='{$wapid}'";
           $result = mysql_query($sql);
	       if($result && mysql_affected_rows()>0){
	       $tip =  "<div class=\"tip\">修改成功</div>";
           }else{
           $tip = "<div class=\"tip\">修改失败</div>";
              }
	       }
		   //修改页面 
		   $sql = "SELECT cssid,csscn,color,csscontent FROM css WHERE cssid={$_GET['id']} AND site='{$wapid}'";
		   $result = mysql_query($sql);
           if($result && mysql_num_rows($result)){
		   list($cssid,$csscn,$color,$csscontent) = mysql_fetch_row($result);
		        $html = '<div class="title">CSS样式修改</div><div class="content">
	            <form method="POST" action="CssSelect.php?action=view&id='.$_GET['id'].'&">
		        样式名称<br>
		        <input type="text" name="csscn" value="'.$csscn.'"/>
				<br>样式颜色<br>
		        <input type="text" name="color" value="'.$color.'"/>
				<br>所属版本<br>
		        <select name="ver">
				<option value="3">3触屏版</option>
				<option value="1">1极速版</option>
				<option value="2">2普通版</option>
				<option value="4">3电脑版</option>
				<option value="5">5特效版</option>
				</select>
				<br>
				<textarea name="csscontent" style="height:200px;">'.$csscontent.'</textarea>
				<input name="type" type="hidden" value="mod" />
				<br><input type="submit" value="提交修改"/>
				</form></div>';
		        }else{
		        $html = '您好，不存在此CSS，请返回重试！';
		     }		   
          		 
        }else{
         $html = '您好，您无权进入此页面！';
	}
         $html = $tip.$html.'<div class="mylink"><a href="CssSelect.php?action=admin&">样式管理</a>|<a href="admin/wap_admin.php?">后台管理</a>
         <br><a href="indexadmin.php?cid='.$_GET['cid'].'&">返回页面综合排版</a></div>';
  }elseif($_GET['action'] == 'add'){
  //添加CSS样式
  if($admin == 1 || $admin == 2){
  require "style/css_add.php";
  }else{
     $html = '您好，您无权进入此页面！';
     }
  }elseif($_GET['action']=='add_css'){
        if($admin==1||$admin==2){
		 $content =$_POST['csscontent']; 
	    $sql = "INSERT INTO css(csscn,csscontent,site,color,mr,ver) VALUES ('{$_POST['csscn']}', '{$content}', '{$wapid}','{$_POST['color']}','0','{$_POST['ver']}')";
	    $add=mysql_query($sql);
		if($add && mysql_affected_rows()>0){
		
		    $html='<div class="tip">CSS提交成功</div>';
	          }else{
	        $html='<div class="tip">CSS提交失败</div>';
	        }
		 }else{
		 $html='<div class="tip">请先登录网站并且保证您具有权限!</div>';
		 }
	  $html='<div class="title">CSS提交</div>'.$html.'<div class="mylink"><a href="?action=admin&">返回上级</a><a href="index.php?">网站首页</a></div>';
  }else{
 //用户页面
function cssLine($ver,$wapid){
    $sql="SELECT cssid,csscn,csscontent,color,site,ver FROM css WHERE site='{$wapid}' AND ver='{$ver}' ORDER BY cssid DESC";  
    $result=mysql_query($sql);      
	if($result && mysql_num_rows($result)>0){
	$i=0;
	while(list($cssid,$csscn,$csscontent,$color,$site,$selver)=mysql_fetch_row($result)){
	$div = $num++%2 == 0?'line1':'line2';
	$html.= '<div class="'.$div.'"><a href="CssSelect.php?cid='.$_GET['cid'].'&id='.$cssid.'&sid='.$GLOBALS['sid1'].'-'.$selver.'-'.$cssid.'"><font color="'.$color.'">'.$csscn.'</font></a></div>';
	 }
	 }else{
	 $html = '<div class="tip">此栏目暂无记录!请联系管理员添加！</div>';
	 }
     mysql_free_result($result);
	 return $html;
	 }
	 $html='<div class="subtitle">极速版</div>
'.cssLine(1,$wapid).'
<div class="subtitle">炫彩版</div>
'.cssLine(2,$wapid).'
<div class="subtitle">触屏版</div>
'.cssLine(3,$wapid).'
<div class="subtitle">电脑版</div>
'.cssLine(4,$wapid).'
<div class="subtitle">HTML5</div>
'.cssLine(5,$wapid);
$html ='<div class="title">更换CSS样式</div>'.$html.'<div class="mylink"><a href="index.php?cid='.$_GET['cid'].'">返回上级</a><a href="index.php?cid=0&sid='.$_GET['cid'].'">返回首页</a></div>';
}
//页面输出；
$html = head('CSS样式').$html.footer(0);
echo UBB($html,$wapid);


?>