<?php

/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0);
include "../../include/cctvai.conn.php";
include "../function_common.php";
admincheck(4);
/*if(Smallfivesolution()==$_SERVER['SERVER_NAME']) {
} else {
	echo Smallfivesq();
	exit();
}*/
$action=SafeRequest("action", "get");
if($action == "unite") {
    global $db;
    $cd_name=SafeRequest("cd_name", "post");
    $cd_classid=SafeRequest("cd_classid", "post");
    $cd_path=SafeRequest("cd_path", "post");
    $cd_points=SafeRequest("cd_points", "post");
    $cd_hits=SafeRequest("cd_hits", "post");
    if($cd_name == "") {
        showmessage("出错了，皮肤名称不能为空！", "userskin.php", 1);
    }
    if($cd_classid == "") {
        showmessage("出错了，皮肤分类不能为空！", "userskin.php", 1);
    }
    if($cd_path == "") {
        showmessage("出错了，皮肤css目录不能为空！", "userskin.php", 1);
    }
    if($cd_points == "") {
        showmessage("出错了，售价金币不能为空！", "userskin.php", 1);
    }
    $sql="Insert " . tname('skin') . " (cd_name,cd_classid,cd_path,cd_points,cd_hits,cd_addtime) values ('" . $cd_name . "','" . $cd_classid . "','" . $cd_path . "','" . $cd_points . "','" . $cd_hits . "','" . time() . "')";
    $db->query($sql);
    showmessage("恭喜您，添加模板皮肤成功！", "userskin.php", 0);
} elseif($action == "editsave") {
    global $db;
    $CD_ID=RequestBox("cd_id");
    if($CD_ID == "0") {
        showmessage("出错了，请选择要编辑的模板皮肤！", "userskin.php", 1);
    } else {
        $ID=explode(",", $CD_ID);

        for($i=0; $i < count($ID); $i++) {
            $cd_name=SafeRequest("cd_name" . $ID[$i] . "", "post");
            $cd_classid=SafeRequest("cd_classid" . $ID[$i] . "", "post");
            $cd_path=SafeRequest("cd_path" . $ID[$i] . "", "post");
            $cd_points=SafeRequest("cd_points" . $ID[$i] . "", "post");
            $cd_hits=SafeRequest("cd_hits" . $ID[$i] . "", "post");
            if($cd_name == "") {
                showmessage("出错了，皮肤名称不能为空！", "userskin.php", 1);
            }
            if($cd_classid == "") {
                showmessage("出错了，皮肤分类不能为空！", "userskin.php", 1);
            }
            if($cd_path == "") {
                showmessage("出错了，皮肤css目录不能为空！", "userskin.php", 1);
            }
            if($cd_points == "") {
                showmessage("出错了，售价金币不能为空！", "userskin.php", 1);
            }
            $sql="update " . tname('skin') . " set cd_name='" . $cd_name . "',cd_classid='" . $cd_classid . "',cd_path='" . $cd_path . "',cd_points='" . $cd_points . "',cd_hits='" . $cd_hits . "',cd_addtime='" . time() . "' where cd_id=" . $ID[$i] . "";
            $db->query($sql);
        }
        showmessage("恭喜您，编辑模板皮肤成功！", "userskin.php", 0);
    }
} elseif($action == "del") {
    global $db;
    $CD_ID=SafeRequest("cd_id", "get");
    $array=array('1','2','3','4','5');
    if(in_array($CD_ID, $array)) {
        showmessage("删除失败,为确保正常运行，您不可以删除默认数据！", "userskin.php", 0);
    }
    $sql="delete from " . tname('skin') . " where cd_id='" . $CD_ID . "'";
    if($db->query($sql)) {
        die("<script>window.location='userskin.php'</script>");
    }
}
?>
<!DOCTYPE html>
<html>
 <head> 
  <meta charset="gbk" /> 
  <meta name="renderer" content="webkit" /> 
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
  <title>后台管理中心</title> 
  <link href="../css/add.css" rel="stylesheet" /> 
  <style type="text/css">
.table2{width: 100%;max-width: 100%;border-collapse: collapse;border-spacing: 0;}
.table2 td{font-size: 12px;border-top: 1px solid #ddd;padding: 8px;vertical-align: top;}
.table2 tr:hover{text-decoration: none;background-color: #e6f2fb;}
.table2 th{border-bottom: 2px solid #ddd;vertical-align: bottom;padding: 2px;text-align: left;}
.table3{width: 100%;max-width: 100%;border-collapse: collapse;border-spacing: 0;}
.table3 tr:hover{text-decoration: none;background-color: #e6f2fb;}
.table3 td{font-size: 12px;line-height:25px;border-top: 1px solid #ddd;padding: 5px;vertical-align: top;border-right: solid 1px #ddd;}
.table3 th{border-bottom: 2px solid #ddd;vertical-align: bottom;padding: 2px;text-align: left;}
</style> 
  <script language="javascript">
function CheckAll(form) {
	for (var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if (e.name != 'chkall')
			e.checked = form.chkall.checked;
	}
}
function MM_jumpMenu(targ, selObj, restore) { //v3.0
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
	if (restore)
		selObj.selectedIndex = 0;
}
</script> 
 </head> 
 <body> 
  <div class="contents"> 
   <div class="panel"> 
    <div style="padding: 8px;"> 
     <a href="userskin.php" class="btn btn_success">所有皮肤</a> 
     <a href="userskinclass.php" class="btn ">模板皮肤分类</a> 
    </div> 
   </div> 
  </div> 
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>会员空间模板(装扮皮肤)管理</strong> 
    </div> 
     <div class="search_type cc mb10"> 
      <div class="ul_wrap"> 
       <ul class="cc"> 
        <li> <label>按分类：</label>
        <select class="select_3" onChange="MM_jumpMenu('self',this,0)"> 
        <option value="userskin.php">选择分类</option> 
<?php
$sqlclass="select * from " . tname('skin_class') . "";
$results=$db->query($sqlclass);
if($results) {
    while($row3=$db->fetch_array($results)) {
        if(SafeRequest("classid", "get") == $row3['cd_id']) {
            echo "<option value='?action=class&classid=" . $row3['cd_id'] . "' selected='selected'>" . $row3['cd_name'] . "</option>";
        } else {
            echo "<option value='?action=class&classid=" . $row3['cd_id'] . "' >" . $row3['cd_name'] . "</option>";
        }

    }
}
?>
        </select> 
        </li> 
       </ul> 
      </div> 
     </div> 
    <form name="form" method="post" action="userskin.php?action=editsave"> 
     <table class="table2" id="dellist"> 
      <tbody> 
       <tr> 
        <td width="60" align="left"> 序号</td> 
        <td width="160" align="left">皮肤名称</td> 
        <td width="160" align="left">所属分类</td> 
        <td width="160" align="left">皮肤css目录</td> 
		<td width="160" align="left">售价金币</td> 
		<td width="160" align="left">人气</td> 
        <td align="left">操作</td> 
       </tr> 
<?php
$classid=SafeRequest("classid", "get");
global $db;
if($classid){
$sql="select * from " . tname('skin') . " where cd_classid='$classid' order by cd_id desc";	
}else{
$sql="select * from " . tname('skin') . " order by cd_id desc";	
}
$result=$db->query($sql);
$videonum=$db->num_rows($result);
if($videonum==0)
	echo "<tr><td height='30' colspan='9' align='center' bgcolor='#FFFFFF' class='td_border'><br><br>没有数据<br><br><br></td></tr>";
if($result) {
	while($row=$db->fetch_array($result)) {
?>
       <tr>
        <td align="left"><input type="checkbox" name="cd_id[]" id="cd_id" value="<?php echo $row['cd_id']?>" class="checkbox"/><?php echo $row['cd_id']?></td>
        <td align="left"><input type="text" class="input input_hd length_2" name="cd_name<?php echo $row['cd_id']?>" value="<?php echo $row['cd_name']?>"/></td>
        <td align="left"><select name="cd_classid<?php echo $row['cd_id']?>" id="cd_classid">
<?php
$sqlclass="select * from " . tname('skin_class') . "";
$results=$db->query($sqlclass);
if($results) {
    while($row3=$db->fetch_array($results)) {
        if($row['cd_classid'] == $row3['cd_id']) {
            echo "        <option value='" . $row3['cd_id'] . "' selected='selected'>" . $row3['cd_name'] . "</option>
";
        } else {
            echo "        <option value='" . $row3['cd_id'] . "' >" . $row3['cd_name'] . "</option>
";
        }
    }
}
?>
        </select></td>
        <td align="left"><input type="text" class="input input_hd length_1" name="cd_path<?php echo $row['cd_id']?>" value="<?php echo $row['cd_path']?>"/></td>
		<td align="left"><input type="text" class="input input_hd length_1" name="cd_points<?php echo $row['cd_id']?>" value="<?php echo $row['cd_points']?>"/></td>
		<td align="left"><input type="text" class="input input_hd length_1" name="cd_hits<?php echo $row['cd_id']?>" value="<?php echo $row['cd_hits']?>"/></td>
        <td align="left"><a onClick="return confirm('确定删除吗？不可恢复！');" href="?action=del&cd_id=<?php echo $row['cd_id']?>" class="btn" style="font-size: 12px;padding: 3px 8px;">删除</a></td>
       </tr>
<?php
}
}
?>
       <tr> 
        <td height="35" colspan="8" align="left" bgcolor="#FAFBF7" class="td_border"><label for="chkall"><input type="checkbox" id="chkall" onClick="CheckAll(this.form)" class="checkbox" />&nbsp;全选</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" name="Submit" value="修改所选栏目" class="btn btn_submit mr10 J_ajax_submit_btn" /></td> 
       </tr> 
      </tbody> 
     </table> 
    </form> 
   </div> 
  </div> 
  <!--添加栏目--> 
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>添加模板皮肤</strong> 
    </div> 
    <form action="?action=unite" name="unite" id="unite" method="post"> 
     <table width="100%"> 
      <tbody>
       <tr> 
        <td height="50" align="left"> &nbsp;
		皮肤名称：<input type="text" class="input input_hd length_2" name="cd_name" id="cd_name" value="" />　 &nbsp;
		所属分类：<select name="cd_classid" id="cd_classid">
<?php
$sqlclass="select * from " . tname('skin_class') . "";
$results=$db->query($sqlclass);
if($results) {
    while($row3=$db->fetch_array($results)) {
        echo "<option value='" . $row3['cd_id'] . "' >" . $row3['cd_name'] . "</option>";
    }
}
?>
        </select>　 
		皮肤css目录： <input id="cd_path" name="cd_path" value="" type="text" class="input input_hd length_1" />&nbsp;&nbsp; &nbsp;
		售价金币：<input id="cd_points" name="cd_points" value="" type="text" class="input input_hd length_1" />&nbsp;&nbsp;
		人气：<input id="cd_hits" name="cd_hits" value="0" type="text" class="input input_hd length_1" /> 
		<input type="submit" value="确定提交" name="submit" class="btn btn_submit mr10 J_ajax_submit_btn" /> 
		</td> 
       </tr> 
      </tbody>
     </table> 
    </form> 
   </div> 
  </div>  
 </body>
</html>