<?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(3);
/*if(Smallfivesolution()==$_SERVER['SERVER_NAME']) {
} else {
	echo Smallfivesq();
	exit();
}*/
$action=SafeRequest("action", "get");
?>
<!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 exchange_type(theForm) {
	if (theForm.CD_SystemID.value == '2') {
		alert("请在 英文别名 处填写跳转网址！");
		document.form1.CD_AliasName.focus();
		return false;
	}
}
</script>
 </head>    
 <body> 
  <div class="contents"> 
   <div class="panel"> 
    <div style="padding: 8px;"> 
     <a href="video.php" class="btn">视频列表</a> 
     <a href="videoclass.php" class="btn">分类栏目管理</a> 
     <a href="videotop.php" class="btn btn_success">视频榜单管理</a> 
     <a href="video.php?action=add" class="btn">添加视频</a> 
     <a href="video.php?action=pass" class="btn">审核视频</a> 
     <a href="video.php?action=isbest" class="btn">星级视频</a> 
     <a href="video.php?action=error" class="btn">报错的视频</a> 
     <a href="video.php?action=deleted" class="btn">视频回收站</a> 
    </div> 
   </div> 
  </div>
<?php
switch($action) {
	case 'del':
		Del();
		break;
	case 'edit':
		Edit();
		break;
	case 'saveseoAdd':
		SaveseoAdd();
		break;
	case 'editishide':
		EditIsHide();
		break;
	case 'editsave':
		EditSave();
		break;
	case 'saveadd':
		SaveAdd();
		break;
	case 'unite':
		Unite();
		break;
	default:
		main();
		break;
}
?>
 </body>
</html>
<?php
function Edit() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "get");
	$sql='select * from ' . tname('videotop') . ' where CD_ID=' . $CD_ID . '';
	$row=$db->getRow($sql);
?>
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>请务必添加标题，关键词，描述。</strong> 
    </div> 
    <table class="table3"> 
     <tbody> 
      <form action="?action=saveseoAdd" method="post" name="form2">
      <tr> 
       <td width="120" align="left" class="p10">栏目ID</td> 
       <td align="left"> <input id="CD_ID" name="CD_ID" value="<?php echo $row['CD_ID']?>" type="text" class="input input_hd length_1" readonly="readonly" /> </td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">栏目名称</td> 
       <td align="left"> <input id="CD_Name" name="CD_Name" value="<?php echo $row['CD_Name']?>" type="text" class="input input_hd length_3" /> </td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">英文别名</td> 
       <td align="left"> <input id="CD_AliasName" name="CD_AliasName" value="<?php echo $row['CD_AliasName']?>" type="text" class="input input_hd length_3" /> </td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">栏目模板</td> 
       <td align="left"> <input id="CD_Template" name="CD_Template" value="<?php echo $row['CD_Template']?>" type="text" class="input input_hd length_3" /> </td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">标题（Title）</td> 
       <td align="left"> <input id="CD_title" name="CD_title" value="<?php echo $row['CD_title']?>" type="text" class="input input_hd length_6" style="width: 450px;" /> </td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">关键词（KeyWords）</td> 
       <td align="left"> <input id="CD_keywords" name="CD_keywords" value="<?php echo $row['CD_keywords']?>" type="text" class="input input_hd length_6" style="width: 450px;" /> </td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">描述（Description）</td> 
       <td align="left"> <textarea class="length_6" name="CD_description" style="width: 450px;"><?php echo $row['CD_description']?></textarea> </td> 
      </tr> 
      <tr> 
       <td height="35" colspan="2" align="left" bgcolor="#FAFBF7" class="td_border"><button type="submit" id="adddance" class="btn btn_submit J_ajax_submit_btn" style="margin-left: 130px;">确定提交</button></td> 
      </tr> 
      <tr>
       <td height="35" colspan="2" align="left" bgcolor="#FAFBF7" class="td_border"> <b>可用标签：[videotop:dname]=&gt;榜单名称　[videotop:dnames]=&gt;所属分类名称　{cctvai:pagenow}=&gt;页数 <br />标题，关键词，描述，作为该分类下的全局应用，务必填写。 <br />优化建议： <br />标题：一般不超过80个字符 （个人建议控制在40个字符左右，能显示完整标题，不会出现省略号。） <br />关键词：一般不超过100个字符 （从低指数排列到高指数，前期控制在3-5个关键词，后期不可超过10个。） <br />描述：一般不超过200个字符 （重复主关键词一次，围绕主关键词拓展词，语句通顺，最好是写的原创。） </b> </td> 
      </tr> 
	  </form> 
     </tbody> 
    </table>  
   </div> 
  </div> 
<?php
}
function main() {
	global $db;
	$sql="select * from " . tname('videotop') . " order by cd_id asc";
	$result=$db->query($sql);
	$classnum=$db->num_rows($result);
?>
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>视频榜单栏目管理,别名只能是英文+数字，请勿使用其他符号</strong> 
    </div> 
    <form name="form" method="post" action="videotop.php?action=editsave"> 
     <table class="table2"> 
      <tbody> 
       <tr> 
        <td width="45" align="left"> 序号</td> 
        <td align="left">栏目名称</td> 
        <td align="left">栏目属性</td> 
        <td align="left">英文别名</td> 
        <td align="left">调用字段</td> 
        <td align="left">栏目模板</td> 
        <td align="left">排序</td> 
        <td align="left">显示</td> 
        <td width="110" align="left">操作</td> 
       </tr> 
<?php
if($classnum==0)
	echo "<tr><td height=\"30\" colspan=\"8\" align=\"center\" bgcolor=\"#FFFFFF\" class=\"td_border\"><br><br>没有数据<br><br><br></td></tr>";
if($result) {
	while($row=$db->fetch_array($result)) {
?>
       <tr> 
        <td><input type="checkbox" name="CD_ID[]" id="CD_ID" value="<?php echo $row['CD_ID']?>" class="checkbox"/><?php echo $row['CD_ID']?></td>
        <td><input type="text" class="classinput k100" name="CD_Name<?php echo $row['CD_ID']?>" value="<?php echo $row['CD_Name']?>"/></td>
        <td><?php if($row['CD_SystemID']==1){?>内部栏目<?php }else{?><font color=red>跳转网址</font><?php }?></td>
        <td><input type="text" class="classinput k100" name="CD_AliasName<?php echo $row['CD_ID']?>" value="<?php echo $row['CD_AliasName']?>"/></td>
        <td> 
        <select name="CD_Type<?php echo $row['CD_ID']?>">
        <option value="CD_AddTime"<?php if($row['CD_Type']=="CD_AddTime"){echo " selected";} ?>>发布时间=>CD_AddTime</option>
        <option value="CD_LastHitTime"<?php if($row['CD_Type']=="CD_LastHitTime"){echo " selected";} ?>>推荐时间=>CD_LastHitTime</option>
        <option value="CD_Hits"<?php if($row['CD_Type']=="CD_Hits"){echo " selected";} ?>>总人气=>CD_Hits</option>
        <option value="CD_DayHits"<?php if($row['CD_Type']=="CD_DayHits"){echo " selected";} ?>>日人气=>CD_DayHits</option>
        <option value="CD_WeekHits"<?php if($row['CD_Type']=="CD_WeekHits"){echo " selected";} ?>>周人气=>CD_WeekHits</option>
        <option value="CD_MonthHits"<?php if($row['CD_Type']=="CD_MonthHits"){echo " selected";} ?>>月人气=>CD_MonthHits</option>
        <option value="CD_FavHits"<?php if($row['CD_Type']=="CD_FavHits"){echo " selected";} ?>>收藏人气=>CD_FavHits</option>
        <option value="CD_DownHits"<?php if($row['CD_Type']=="CD_DownHits"){echo " selected";} ?>>下载人气=>CD_DownHits</option>
        <option value="CD_Grade-0"<?php if($row['CD_Type']=="CD_Grade-0"){echo " selected";} ?>>游客下载权限=>CD_Grade-0</option>
        <option value="CD_Grade-1"<?php if($row['CD_Type']=="CD_Grade-1"){echo " selected";} ?>>普通下载权限=>CD_Grade-1</option>
        <option value="CD_Grade-2"<?php if($row['CD_Type']=="CD_Grade-2"){echo " selected";} ?>>VIP下载权限=>CD_Grade-2</option>
        <option value="CD_Siz"<?php if($row['CD_Type']=="CD_Siz"){echo " selected";} ?>>文件大小=>CD_Siz</option>
        <option value="CD_IsBest"<?php if($row['CD_Type']=="CD_IsBest"){echo " selected";} ?>>星级=>CD_IsBest</option>
        <option value="CD_Playtime"<?php if($row['CD_Type']=="CD_Playtime"){echo " selected";} ?>>时长=>CD_Playtime</option>
        <option value="CD_Bitkbps"<?php if($row['CD_Type']=="CD_Bitkbps"){echo " selected";} ?>>码率=>CD_Bitkbps</option>
        <option value="CD_Points"<?php if($row['CD_Type']=="CD_Points"){echo " selected";} ?>>售价=>CD_Points</option>
        <option value="CD_uHits"<?php if($row['CD_Type']=="CD_uHits"){echo " selected";} ?>>顶=>CD_uHits</option>
        <option value="CD_dHits"<?php if($row['CD_Type']=="CD_dHits"){echo " selected";} ?>>踩=>CD_dHits</option>
        </select>
        </td> 
        <td><input type="text" name="CD_Template<?php echo $row['CD_ID']?>" value="<?php echo $row['CD_Template']?>" class="classinput"/></td>
        <td align="left"><input type="text" class="classinput k20" name="CD_TheOrder<?php echo $row['CD_ID']?>" value="<?php echo $row['CD_TheOrder']?>" onKeyUp="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/></td>
        <td align="left"><?php if($row['CD_IsHide']==1){?><a href="?action=editishide&CD_ID=<?php echo $row['CD_ID']?>&CD_IsHide=0"><img src='images/no.gif' border='0'></a><?php }else{?><a href="?action=editishide&CD_ID=<?php echo $row['CD_ID']?>&CD_IsHide=1"><img src='images/yes.gif' border='0'></a><?php }?></td>
        <td align="left"> <a href="?action=edit&CD_ID=<?php echo $row['CD_ID']?>" class="btn" style="font-size: 12px;padding: 3px 8px;">设置</a><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>添加分类栏目 注意：选跳转网址的请在英文别名填上http地址</strong> 
    </div> 
    <form id="form1" name="form1" method="post" action="?action=saveadd"> 
     <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
      <tbody>
       <tr> 
        <td height="30" align="center" bgcolor="#FFFFFF" class="td_border">栏目名称</td> 
        <td align="center" bgcolor="#FFFFFF" class="td_border">英文别名</td> 
        <td align="center" bgcolor="#FFFFFF" class="td_border">调用字段</td> 
        <td align="center" bgcolor="#FFFFFF" class="td_border">栏目属性</td> 
        <td align="center" bgcolor="#FFFFFF" class="td_border">栏目模板</td> 
        <td align="center" bgcolor="#FFFFFF" class="td_border">排序</td> 
        <td align="center" bgcolor="#FFFFFF" class="td_border">状态</td> 
        <td align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;</td> 
       </tr> 
       <tr> 
        <td height="30" align="center"><input type="text" class="classinput k100" name="CD_Name" id="CD_Name" value="" /></td> 
        <td height="30" align="center"><input type="text" class="classinput k100" name="CD_AliasName" id="CD_AliasName" value="" size="50" /></td> 
        <td height="30" align="center"><select name="CD_Type"> <option value="CD_AddTime">发布时间=&gt;CD_AddTime</option> <option value="CD_LastHitTime">推荐时间=&gt;CD_LastHitTime</option> <option value="CD_Hits">总人气=&gt;CD_Hits</option> <option value="CD_DayHits">日人气=&gt;CD_DayHits</option> <option value="CD_WeekHits">周人气=&gt;CD_WeekHits</option> <option value="CD_MonthHits">月人气=&gt;CD_MonthHits</option> <option value="CD_FavHits">收藏人气=&gt;CD_FavHits</option> <option value="CD_DownHits">下载人气=&gt;CD_DownHits</option> <option value="CD_Grade-0">游客下载权限=&gt;CD_Grade-0</option> <option value="CD_Grade-1">普通下载权限=&gt;CD_Grade-1</option> <option value="CD_Grade-2">VIP下载权限=&gt;CD_Grade-2</option> <option value="CD_Siz">文件大小=&gt;CD_Siz</option> <option value="CD_IsBest">星级=&gt;CD_IsBest</option> <option value="CD_Playtime">时长=&gt;CD_Playtime</option> <option value="CD_Bitkbps">码率=&gt;CD_Bitkbps</option> <option value="CD_Points">售价=&gt;CD_Points</option> <option value="CD_uHits">顶=&gt;CD_uHits</option> <option value="CD_dHits">踩=&gt;CD_dHits</option> </select> </td> 
        <td height="30" align="center"><select name="CD_SystemID" id="CD_SystemID" onChange="exchange_type(form1)"><option value="1">内部栏目</option><option value="2">跳转网址</option></select></td> 
        <td height="30" align="center"><input name="CD_Template" type="text" class="classinput k100" id="CD_Template" value="video_top.html" /></td> 
        <td height="30" align="center"><input type="text" name="CD_TheOrder" class="classinput k20" id="CD_TheOrder" value="0" size="5" onKeyUp="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" /></td> 
        <td height="30" align="center"><select name="CD_IsHide"><option value="0">显示</option><option value="1">隐藏</option></select></td> 
        <td align="center" class="td_border"><input type="submit" name="button" id="addvc" value="提 交" class="btn btn_submit mr10 J_ajax_submit_btn" /></td> 
       </tr> 
       <tr> 
        <td height="3" colspan="7">&nbsp;</td> 
       </tr> 
      </tbody>
     </table> 
    </form> 
   </div> 
  </div> 
<?php
}
//执行保存
function SaveseoAdd() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "post");
	$CD_Name=SafeRequest("CD_Name", "post");
	$CD_AliasName=SafeRequest("CD_AliasName", "post");
	$CD_Template=SafeRequest("CD_Template", "post");
	$CD_title=SafeRequest("CD_title", "post");
	$CD_keywords=SafeRequest("CD_keywords", "post");
	$CD_description=SafeRequest("CD_description", "post");
	$sql="update " . tname('videotop') . " set CD_Name='" . $CD_Name . "',CD_AliasName='" . $CD_AliasName . "',CD_Template='" . $CD_Template . "',CD_title='" . $CD_title . "',CD_keywords='" . $CD_keywords . "',CD_description='" . $CD_description . "' where CD_ID=" . $CD_ID . "";
	$db->query($sql);
	showmessage("恭喜您，编辑栏目成功！", $_SERVER['HTTP_REFERER'], 0);
}

function SaveAdd() {
	global $db;
	$CD_Name=SafeRequest("CD_Name", "post");
	$CD_AliasName=SafeRequest("CD_AliasName", "post");
	$CD_TheOrder=SafeRequest("CD_TheOrder", "post");
	$CD_Template=SafeRequest("CD_Template", "post");
	$CD_IsHide=SafeRequest("CD_IsHide", "post");
	$CD_SystemID=SafeRequest("CD_SystemID", "post");
	$CD_Type=SafeRequest("CD_Type", "post");
	if(!IsNul($CD_Name)) {
		showmessage("出错了，栏目名称不能为空！", "videotop.php", 1);
	}
	if(!IsNul($CD_AliasName)) {
		showmessage("出错了，英文别名不能为空！", "videotop.php", 1);
	}
	if(!IsNul($CD_Template)) {
		showmessage("出错了，栏目模板不能为空！", "videotop.php", 1);
	}
	if(!IsNum($CD_TheOrder)) {
		showmessage("出错了，排序不能为空！", "videotop.php", 1);
	}
	$sql="Insert " . tname('videotop') . " (CD_Name,CD_AliasName,CD_FatherID,CD_TheOrder,CD_Template,CD_IsHide,CD_SystemID,CD_Type) values ('" . $CD_Name . "','" . $CD_AliasName . "',0," . $CD_TheOrder . ",'" . $CD_Template . "',0," . $CD_SystemID . ",'" . $CD_Type . "')";
	$db->query($sql);
	showmessage("恭喜您，添加栏目成功！", "videotop.php", 0);
}

function EditSave() {
	global $db;
	$CD_ID=RequestBox("CD_ID");
	if($CD_ID=="0") {
		showmessage("出错了，请选择要编辑的栏目！", "videotop.php", 1);
	} else {
		$ID=explode(",", $CD_ID);

		for($i=0; $i<count($ID); $i++) {
			$CD_Name=SafeRequest("CD_Name" . $ID[$i] . "", "post");
			$CD_AliasName=SafeRequest("CD_AliasName" . $ID[$i] . "", "post");
			$CD_Template=SafeRequest("CD_Template" . $ID[$i] . "", "post");
			$CD_TheOrder=SafeRequest("CD_TheOrder" . $ID[$i] . "", "post");
			$CD_Type=SafeRequest("CD_Type" . $ID[$i] . "", "post");
			if(!IsNul($CD_Name)) {
				showmessage("出错了，栏目名称不能为空！", "videotop.php", 1);
			}
			if(!IsNul($CD_AliasName)) {
				showmessage("出错了，英文别名不能为空！", "videotop.php", 1);
			}
			if(!IsNul($CD_Template)) {
				showmessage("出错了，栏目模板不能为空！", "videotop.php", 1);
			}
			if(!IsNum($CD_TheOrder)) {
				showmessage("出错了，排序不能为空！", "videotop.php", 1);
			}
			$sql="update " . tname('videotop') . " set CD_Name='" . $CD_Name . "',CD_AliasName='" . $CD_AliasName . "',CD_Template='" . $CD_Template . "',CD_TheOrder=" . $CD_TheOrder . ",CD_Type='" . $CD_Type . "' where CD_ID=" . $ID[$i] . "";
			$db->query($sql);
		}
		showmessage("恭喜您，编辑栏目成功！", "videotop.php", 0);
	}

}

function EditIsHide() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "get");
	$CD_IsHide=SafeRequest("CD_IsHide", "get");
	$sql="update " . tname('videotop') . " set CD_IsHide=" . $CD_IsHide . " where CD_ID=" . $CD_ID . "";
	if($db->query($sql)) {
		echo "<script>window.location='videotop.php'</script>";
	}
}

function del() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "get");
	$array=array('1','2','3','4','5','6','7');
	if(in_array($CD_ID, $array)) {
		showmessage("删除失败,系统自带栏目您只可以编辑不可删除。", "videotop.php", 0);
	}
	$sql="delete from " . tname('videotop') . " where CD_ID='" . $CD_ID . "'";
	if($db->query($sql)) {
		showmessage("恭喜您，删除栏目成功！", "videotop.php", 0);
	}else{
		showmessage("出错了，删除栏目失败！", "videotop.php", 0);
	}
}
?>