<?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: 5px !important;vertical-align: top;}
.table2 td a img{margin-top: 5px;}
.table2 tr:hover{text-decoration: none;background-color: #F5F9FD;}
.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;}
.classfid td{font-size: 12px;border-top: 0px solid #ddd;padding: 5px !important;vertical-align: top;}
.board{padding-left: 75px;background: url(images/bg_repno.gif) no-repeat -220px -550px;float: left;}
.classinput{padding: 2px;border-radius: 0px;height: 16px;padding: 2px 5px;float: left;}
.hover:hover .addchildboard, .hover:hover .deleterow{color: #F5F9FD;}
.addchildboard:hover, .deleterow:hover{text-decoration: none;color: #F60 !important;}
.addchildboard, .deleterow{margin-right: 5px;padding-left: 17px;line-height: 25px;background: url(images/bg_repno.gif) no-repeat 0 -599px;color: #FFF;zoom: 1;}
</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="newsclass.php" class="btn btn_success">栏目管理</a> 
     <a href="news.php" class="btn ">文章管理</a> 
     <a href="news.php?action=newsadd" class="btn ">添加文章</a> 
     <a href="news.php?action=classc&CD_ClassID=1" class="btn ">公告管理</a> 
     <a href="news.php?action=newsggadd&bid=1" class="btn ">添加公告</a> 
    </div> 
   </div> 
  </div> 
<?php
switch($action) {
	case 'del':
		Del();
		break;
	case 'delz':
		Delz();
		break;
	case 'Fedit':
		FEdit();
		break;
	case 'Zedit':
		Zedit();
		break;
	case 'saveseoAdd':
		SaveseoAdd();
		break;
	case 'saveseozAdd':
		SaveseozAdd();
		break;
	case 'editishide':
		EditIsHide();
		break;
	case 'editsave':
		EditSave();
		break;
	case 'Fsaveadd':
		FSaveAdd();
		break;
	case 'Zsaveadd':
		ZSaveAdd();
		break;
	case 'saveAdd':
		SaveAdd();
		break;
	case 'savezAdd':
		SavezAdd();
		break;
	case 'sunite':
		Sunite();
		break;
	case 'unite':
		Unite();
		break;
	default:
		main();
		break;
}
?> 
 </body>
</html>
<?php
function FEdit() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "get");
	$row=$db->getRow('select * from ' . tname('newsclass') . " where CD_ID='" . $CD_ID . "'");
?>
  <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" /><input type="hidden" name="CD_FatherID" id="CD_FatherID" value="<?php echo $row['CD_FatherID']?>" /> </td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">栏目排序</td> 
       <td align="left"> <input id="CD_TheOrder" name="CD_TheOrder" value="<?php echo $row['CD_TheOrder']?>" type="text" class="input input_hd length_1" /> </td> 
      </tr> 
       <tr> 
        <td align="left">栏目状态</td> 
        <td align="left">
        <select name="CD_IsHide" id="CD_IsHide"> 
        <option value="0" <?php if ($row['CD_IsHide'] == "0") {echo "selected";} ?>>显示</option> 
        <option value="1" <?php if ($row['CD_IsHide'] == "1") {echo "selected";} ?>>隐藏</option> 
        </select>
		</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" /><font color="#d01f3c">&nbsp;&nbsp;唯一的英文别名，不能与其他重复。</font></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>可用标签：　{cctvai:pagenow}=&gt;页数 <br />爱频道参照百度算法给您的SEO建议： <br />标题，关键词，描述，作为该分类下的全局应用，务必填写。 <br />优化建议： <br />标题：一般不超过80个字符 （个人建议控制在40个字符左右，能显示完整标题，不会出现省略号。） <br />关键词：一般不超过100个字符 （从低指数排列到高指数，前期控制在3-5个关键词，后期不可超过10个。） <br />描述：一般不超过200个字符 （重复主关键词一次，围绕主关键词拓展词，语句通顺，最好是写的原创。） </b> </td> 
      </tr> 
	  </form>
     </tbody> 
    </table>  
   </div> 
  </div>
<?php
}
function FSaveAdd() {
?>
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>添加分类</strong> 
    </div> 
    <table class="table3"> 
     <tbody> 
      <form action="?action=saveAdd" method="post" name="form2"> 
      <tr> 
       <td width="120" align="left" class="p10">栏目排序</td> 
       <td align="left"> <input id="CD_TheOrder" name="CD_TheOrder" value="0" type="text" class="input input_hd length_1" /> <input type="hidden" name="CD_FatherID" id="CD_FatherID" value="0" /></td> 
      </tr> 
       <tr> 
        <td align="left">栏目状态</td> 
        <td align="left">
        <select name="CD_IsHide" id="CD_IsHide"> 
        <option value="0">显示</option> 
        <option value="1">隐藏</option> 
        </select>
		</td> 
       </tr> 
      <tr> 
       <td align="left" class="p10">栏目名称</td> 
       <td align="left"> <input id="CD_Name" name="CD_Name" value="" 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="" type="text" class="input input_hd length_3" /> <font color="#d01f3c">&nbsp;&nbsp;唯一的英文别名，不能与其他重复。</font></td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">栏目模板</td> 
       <td align="left"> <input id="CD_Template" name="CD_Template" value="news_list.html" 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="" 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="" 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;"></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>可用标签：　{cctvai:pagenow}=&gt;页数 <br />爱频道参照百度算法给您的SEO建议： <br />标题，关键词，描述，作为该分类下的全局应用，务必填写。 <br />优化建议： <br />标题：一般不超过80个字符 （个人建议控制在40个字符左右，能显示完整标题，不会出现省略号。） <br />关键词：一般不超过100个字符 （从低指数排列到高指数，前期控制在3-5个关键词，后期不可超过10个。） <br />描述：一般不超过200个字符 （重复主关键词一次，围绕主关键词拓展词，语句通顺，最好是写的原创。） </b> </td> 
      </tr> 
	  </form>
     </tbody> 
    </table>  
   </div> 
  </div>
<?php
}
function ZEdit() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "get");
	$row=$db->getRow('select * from ' . tname('newsclass') . " where CD_ID='" . $CD_ID . "'");
?>
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>修改子分类</strong> 
    </div> 
    <table class="table3"> 
     <tbody> 
      <form action="?action=saveseozAdd" 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" /> <input type="hidden" name="CD_FID" id="CD_FID" value="<?php echo $row['CD_FatherID']?>" /></td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">栏目排序</td> 
       <td align="left"> <input id="CD_TheOrder" name="CD_TheOrder" value="<?php echo $row['CD_TheOrder']?>" type="text" class="input input_hd length_1" /> </td> 
      </tr> 
       <tr> 
        <td align="left">栏目状态</td> 
        <td align="left">
        <select name="CD_IsHide" id="CD_IsHide"> 
        <option value="0" <?php if ($row['CD_IsHide'] == "0") {echo "selected";} ?>>显示</option> 
        <option value="1" <?php if ($row['CD_IsHide'] == "1") {echo "selected";} ?>>隐藏</option> 
        </select>
		</td> 
       </tr> 
      <tr> 
       <td align="left" class="p10">上级分类</td> 
       <td align="left">
	   <select name="CD_FatherID" id="CD_FatherID">
<?php
$sqlclass="select * from " . tname('newsclass') . " where CD_FatherID=0 ";
$results=$db->query($sqlclass);
if($results) {
	while($row3=$db->fetch_array($results)) {
		if($row['CD_FatherID']==$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> 
      </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" /> <font color="#d01f3c">&nbsp;&nbsp;唯一的英文别名，不能与其他重复。</font></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>可用标签：　{cctvai:pagenow}=&gt;页数 <br />爱频道参照百度算法给您的SEO建议： <br />标题，关键词，描述，作为该分类下的全局应用，务必填写。 <br />优化建议： <br />标题：一般不超过80个字符 （个人建议控制在40个字符左右，能显示完整标题，不会出现省略号。） <br />关键词：一般不超过100个字符 （从低指数排列到高指数，前期控制在3-5个关键词，后期不可超过10个。） <br />描述：一般不超过200个字符 （重复主关键词一次，围绕主关键词拓展词，语句通顺，最好是写的原创。） </b> </td> 
      </tr> 
	  </form>
     </tbody> 
    </table>  
   </div> 
  </div>
<?php
}
function ZSaveAdd() {
?>
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>添加子分类</strong> 
    </div> 
    <table class="table3"> 
     <tbody> 
      <form action="?action=savezAdd" method="post" name="form2"> 
      <tr> 
       <td width="120" align="left" class="p10">栏目排序</td> 
       <td align="left"> <input id="CD_TheOrder" name="CD_TheOrder" value="0" type="text" class="input input_hd length_1" /> </td> 
      </tr> 
       <tr> 
        <td align="left">栏目状态</td> 
        <td align="left">
        <select name="CD_IsHide" id="CD_IsHide"> 
        <option value="0">显示</option> 
        <option value="1">隐藏</option> 
        </select>
		</td> 
       </tr> 
      <tr> 
       <td align="left" class="p10">上级分类</td> 
       <td align="left">
	   <select name="CD_FatherID" id="CD_FatherID">
<?php
global $db;
$CD_ID=SafeRequest("CD_ID", "get");
$sqlclass="select * from " . tname('newsclass') . " where CD_FatherID=0 ";
$results=$db->query($sqlclass);
if($results) {
	while($row3=$db->fetch_array($results)) {
		if($CD_ID==$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> 
      </tr>
      <tr> 
       <td align="left" class="p10">栏目名称</td> 
       <td align="left"> <input id="CD_Name" name="CD_Name" value="" 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="" type="text" class="input input_hd length_3" /> <font color="#d01f3c">&nbsp;&nbsp;唯一的英文别名，不能与其他重复。</font></td> 
      </tr> 
      <tr> 
       <td align="left" class="p10">栏目模板</td> 
       <td align="left"> <input id="CD_Template" name="CD_Template" value="news_list.html" 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="" 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="" 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;"></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>可用标签：　{cctvai:pagenow}=&gt;页数 <br />爱频道参照百度算法给您的SEO建议： <br />标题，关键词，描述，作为该分类下的全局应用，务必填写。 <br />优化建议： <br />标题：一般不超过80个字符 （个人建议控制在40个字符左右，能显示完整标题，不会出现省略号。） <br />关键词：一般不超过100个字符 （从低指数排列到高指数，前期控制在3-5个关键词，后期不可超过10个。） <br />描述：一般不超过200个字符 （重复主关键词一次，围绕主关键词拓展词，语句通顺，最好是写的原创。） </b> </td> 
      </tr> 
	  </form>
     </tbody> 
    </table>  
   </div> 
  </div>
<?php
}
function main() {
?>
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>分类栏目管理</strong> 
    </div> 
    <div style="padding: 8px;"> 
     <a href="?action=Fsaveadd" class="btn btn-default">添加分类</a> 
	 <a href="?action=sunite" class="btn btn-default">数据转移</a> 
    </div> 
    <form name="form" method="post" action="?action=editsave"> 
     <table class="table2"> 
      <tbody> 
       <tr> 
        <td width="25" align="left"> 选择</td> 
		<td align="left"> ID</td>
        <td align="left">栏目名称</td> 
        <td align="left">英文别名</td> 
        <td align="left">栏目模板</td> 
        <td align="left">排序</td> 
        <td align="left">显示</td> 
        <td width="150" align="left">操作</td> 
       </tr> 
<?php
function Get_Fclass($id) { 
global $db;
$Fsql="select * from " . tname('newsclass') . " where CD_FatherID='".$id."' order by CD_TheOrder asc";
$Fresult=$db->query($Fsql);
    if($Fresult && $db->num_rows($Fresult)){
        while($Frow=$db->fetch_array($Fresult)) { 
		if($Frow['CD_IsHide']==1){$CD_IsHide='<a href="?action=editishide&CD_ID='.$Frow['CD_ID'].'&CD_IsHide=0"><img src="images/no.gif" border="0"></a>';}else{$CD_IsHide='<a href="?action=editishide&CD_ID='.$Frow['CD_ID'].'&CD_IsHide=1"><img src="images/yes.gif" border="0"></a>';}
		if(cd_webnewshtml=="1"){$classurl='../'.cd_webmlnews.'/?0,'.$Frow['CD_AliasName'].',1.html';}else{$classurl='../'.cd_webmlnews.'/?0,'.$Frow['CD_ID'].',1.html';}
            $str .= '       <tr class="classfid"> 
        <td><input type="checkbox" name="CD_ID[]" id="CD_ID" value="'.$Frow['CD_ID'].'" class="checkbox" /></td> 
		<td align="left"><input type="text" class="classinput k20" value="'.$Frow['CD_ID'].'" readonly="readonly"/></td>
        <td><div class="board"><input type="text" class="classinput k100" name="CD_Name'.$Frow['CD_ID'].'" value="'.$Frow['CD_Name'].'"/></div></td> 
        <td><input type="text" class="classinput k100" name="CD_AliasName'.$Frow['CD_ID'].'" value="'.$Frow['CD_AliasName'].'"/></td> 
        <td><input type="text" name="CD_Template'.$Frow['CD_ID'].'" value="'.$Frow['CD_Template'].'" class="classinput"/></td>
        <td align="left"><input type="text" class="classinput k20" name="CD_TheOrder'.$Frow['CD_ID'].'" value="'.$Frow['CD_TheOrder'].'" onkeyup="this.value=this.value.replace(/[^\d]/g,"")" onbeforepaste="clipboardData.setData("text",clipboardData.getData("text").replace(/[^\d]/g,""))"/></td> 
        <td align="left">'.$CD_IsHide.'</td> 
        <td align="left">
		<input type="button" value="预览" onclick="window.open(\''.$classurl.'\',\'list\')" class="btn" style="font-size: 12px;padding: 3px 8px;"> 
		<a href="?action=Zedit&CD_ID='.$Frow['CD_ID'].'" class="btn" style="font-size: 12px;padding: 3px 8px;">设置</a>
		<a onclick="return confirm(\'确定删除吗？不可恢复！\');" href="?action=delz&CD_ID='.$Frow['CD_ID'].'&CD_FID='.$Frow['CD_FatherID'].'" class="btn" style="font-size: 12px;padding: 3px 8px;">删除</a>
        </td>
       </tr>';
            Get_Fclass($Frow['CD_ID']); 
        } 
    } 
    return $str; 
}
global $db;
$sql="select * from " . tname('newsclass') . " where CD_FatherID=0 order by CD_TheOrder asc";
$result=$db->query($sql);
$classnum=$db->num_rows($result);
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" /></td> 
		<td align="left"><input type="text" class="classinput k20" value="<?php echo $row['CD_ID']?>" readonly="readonly"/></td> 
        <td><input type="text" class="classinput k100" name="CD_Name<?php echo $row['CD_ID']?>" value="<?php echo $row['CD_Name']?>" />&nbsp;&nbsp;<a href="?action=Zsaveadd&CD_ID=<?php echo $row['CD_ID']?>" class="addchildboard">添加子分类</a></td> 
        <td><input type="text" class="classinput k100" name="CD_AliasName<?php echo $row['CD_ID']?>" value="<?php echo $row['CD_AliasName']?>"/></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">
		<input type="button" value="预览" onClick="window.open('<?php if(cd_webnewshtml=="1"){echo'../'.cd_webmlnews.'/?0,'.$row['CD_AliasName'].',1.html';}else{echo'../'.cd_webmlnews.'/?0,'.$row['CD_ID'].',1.html';}?>','list')" class="btn" style="font-size: 12px;padding: 3px 8px;"> 
		<a href="?action=Fedit&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
echo get_Fclass($row['CD_ID']);				
}
}
?>
       <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>
<?php
}
function sunite() {
?>  
<!--转移栏目数据-->
  <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" bgcolor="#FFFFFF" class="td_border">&nbsp;将栏目： 
		<select size="1" name="Type_1">
		<option value="">选择栏目</option> 
<?php
global $db;
$sql="select CD_ID,CD_Name from " . tname('newsclass') . " where CD_FatherID=0 order by CD_TheOrder asc";
$result=$db->query($sql);
$classnum=$db->num_rows($result);
if($result) {
	while($row=$db->fetch_array($result)) {
?>
<option value="<?php echo $row['CD_ID']?>" >&nbsp;|—<?php echo $row['CD_Name']?></option>
<?php
echo Get_Fclass_select($row['CD_ID'],'newsclass');				
}
}
?>
		</select> 的数据转移到 
		<select size="1" name="Type_2">
		<option value="">选择栏目</option>
<?php
global $db;
$sql="select CD_ID,CD_Name from " . tname('newsclass') . " where CD_FatherID=0 order by CD_TheOrder asc";
$result=$db->query($sql);
$classnum=$db->num_rows($result);
if($result) {
	while($row=$db->fetch_array($result)) {
?>
<option value="<?php echo $row['CD_ID']?>" >&nbsp;|—<?php echo $row['CD_Name']?></option>
<?php
echo Get_Fclass_select($row['CD_ID'],'newsclass');				
}
}
?>
		</select> 
		<input type="submit" value="确定转移" onClick="return confirm('确定转移吗？不可恢复！');" name="submit" class="btn btn_submit mr10 J_ajax_submit_btn" /></td> 
       </tr> 
       <tr> 
       </tr> 
      </tbody>
     </table> 
    </form> 
   </div> 
  </div>
<?php
}
//执行保存
function SaveseoAdd() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "post");
	$CD_FatherID=SafeRequest("CD_FatherID", "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");
	$CD_TheOrder=SafeRequest("CD_TheOrder", "post");
	$CD_IsHide=SafeRequest("CD_IsHide", "post");
	$sql="update " . tname('newsclass') . " set CD_FatherID='" . $CD_FatherID . "',CD_Name='" . $CD_Name . "',CD_AliasName='" . $CD_AliasName . "',CD_Template='" . $CD_Template . "',CD_title='" . $CD_title . "',CD_keywords='" . $CD_keywords . "',CD_description='" . $CD_description . "',CD_TheOrder='" . $CD_TheOrder . "',CD_IsHide='" . $CD_IsHide . "' where CD_ID=" . $CD_ID . "";
	$db->query($sql);
	showmessage("恭喜您，编辑栏目成功！", $_SERVER['HTTP_REFERER'], 0);
}

function SaveseozAdd() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "post");
	$CD_FatherID=SafeRequest("CD_FatherID", "post");
	$CD_FID=SafeRequest("CD_FID", "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");
	$CD_TheOrder=SafeRequest("CD_TheOrder", "post");
	$CD_IsHide=SafeRequest("CD_IsHide", "post");
	$sql="update " . tname('newsclass') . " set CD_FatherID='" . $CD_FatherID . "',CD_Name='" . $CD_Name . "',CD_AliasName='" . $CD_AliasName . "',CD_Template='" . $CD_Template . "',CD_title='" . $CD_title . "',CD_keywords='" . $CD_keywords . "',CD_description='" . $CD_description . "',CD_TheOrder='" . $CD_TheOrder . "',CD_IsHide='" . $CD_IsHide . "' where CD_ID=" . $CD_ID . "";
	$db->query($sql);
	if($CD_FID!==$CD_FatherID){
		$sqlclass="select * from " . tname('newsclass') . " where CD_FatherID='".$CD_FID."' and CD_ID<>$CD_ID";
		$results=$db->query($sqlclass);
		if($results) {
			while($row3=$db->fetch_array($results)) {
				$CD_TieID.=$row3["CD_ID"].',';
				$a=$a+1;
				}
		}
				$CD_TieID=rtrim($CD_TieID, ',');
				if($a>0){
					$db->query('update ' . tname('newsclass') . " set CD_TieID='".$CD_TieID."' where CD_ID='".$CD_FID."'");
					}else{
						$db->query('update ' . tname('newsclass') . " set CD_TieID='999999' where CD_ID='".$CD_FID."'");
						}
				$db->query('update ' . tname('newsclass') . " set CD_TieID='".$CD_TieID."' where CD_ID in (".$CD_TieID.")");
	
		$Nsqlclass="select * from " . tname('newsclass') . " where CD_FatherID='".$CD_FatherID."'";
		$Nresults=$db->query($Nsqlclass);
		if($Nresults) {
			while($Nrow3=$db->fetch_array($Nresults)) {
				$NCD_TieID.=$Nrow3["CD_ID"].',';
				$b=$b+1;
				}
		}
				$NCD_TieID=rtrim($NCD_TieID, ',');
				if($b>0){
					$db->query('update ' . tname('newsclass') . " set CD_TieID='".$NCD_TieID."' where CD_ID='".$CD_FatherID."'");
					}else{
						$db->query('update ' . tname('newsclass') . " set CD_TieID='999999' where CD_ID='".$CD_FatherID."'");
						}
				$db->query('update ' . tname('newsclass') . " set CD_TieID='".$NCD_TieID."' where CD_ID in (".$NCD_TieID.")");
				
	}

	showmessage("恭喜您，编辑栏目成功！", $_SERVER['HTTP_REFERER'], 0);
}

function Unite() {
	global $db;
	$classa=SafeRequest("Type_1", "post");
	$classb=SafeRequest("Type_2", "post");
	if(!IsNul($classa)|!IsNul($classb)) {
		showmessage("出错了，请选择要转移的栏目！", "newsclass.php", 0);
	}
	$sql="select * from " . tname('news') . " where CD_ClassID=" . $classa . "";
	$result=$db->query($sql);
	if($result) {
		while($row=$db->fetch_array($result)) {
			$sqlstr="update " . tname('news') . " set CD_ClassID=" . $classb . " where CD_ID=" . $row['CD_ID'] . "";
			$db->query($sqlstr);
		}
		showmessage("恭喜您，数据转移成功！", "newsclass.php", 0);
	}
}

function SaveAdd() {
	global $db;
	$CD_FatherID=SafeRequest("CD_FatherID", "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");
	$CD_TheOrder=SafeRequest("CD_TheOrder", "post");
	$CD_IsHide=SafeRequest("CD_IsHide", "post");
	if(!IsNul($CD_Name)) {
		showmessage("出错了，栏目名称不能为空！", "newsclass.php", 1);
	}
	if(!IsNul($CD_AliasName)) {
		showmessage("出错了，英文别名不能为空！", "newsclass.php", 1);
	}
	if(!IsNul($CD_Template)) {
		showmessage("出错了，栏目模板不能为空！", "newsclass.php", 1);
	}
	if(!IsNum($CD_TheOrder)) {
		showmessage("出错了，排序不能为空！", "newsclass.php", 1);
	}
	if(!IsNum($CD_IsHide)) {
		showmessage("出错了，栏目状态不能为空！", "newsclass.php", 1);
	}
	if(!IsNum($CD_FatherID)) {
		showmessage("出错了，上级分类不能为空！", "newsclass.php", 1);
	}
	$sql="Insert " . tname('newsclass') . " (CD_FatherID,CD_Name,CD_AliasName,CD_Template,CD_title,CD_keywords,CD_description,CD_TheOrder,CD_IsHide,CD_SystemID,CD_TieID) values ('".$CD_FatherID."','".$CD_Name."','".$CD_AliasName."','".$CD_Template."','".$CD_title."','".$CD_keywords."','".$CD_description."','".$CD_TheOrder."','".$CD_IsHide."','1','999999')";
	$db->query($sql);
	showmessage("恭喜您，添加栏目成功！", "newsclass.php", 0);
}

function SavezAdd() {
	global $db;
	$CD_FatherID=SafeRequest("CD_FatherID", "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");
	$CD_TheOrder=SafeRequest("CD_TheOrder", "post");
	$CD_IsHide=SafeRequest("CD_IsHide", "post");
	if(!IsNul($CD_Name)) {
		showmessage("出错了，栏目名称不能为空！", "newsclass.php", 1);
	}
	if(!IsNul($CD_AliasName)) {
		showmessage("出错了，英文别名不能为空！", "newsclass.php", 1);
	}
	if(!IsNul($CD_Template)) {
		showmessage("出错了，栏目模板不能为空！", "newsclass.php", 1);
	}
	if(!IsNum($CD_TheOrder)) {
		showmessage("出错了，排序不能为空！", "newsclass.php", 1);
	}
	if(!IsNum($CD_IsHide)) {
		showmessage("出错了，栏目状态不能为空！", "newsclass.php", 1);
	}
	if(!IsNum($CD_FatherID)) {
		showmessage("出错了，上级分类不能为空！", "newsclass.php", 1);
	}
	
	$sql="Insert " . tname('newsclass') . " (CD_FatherID,CD_Name,CD_AliasName,CD_Template,CD_title,CD_keywords,CD_description,CD_TheOrder,CD_IsHide,CD_SystemID,CD_TieID) values ('".$CD_FatherID."','".$CD_Name."','".$CD_AliasName."','".$CD_Template."','".$CD_title."','".$CD_keywords."','".$CD_description."','".$CD_TheOrder."','".$CD_IsHide."','1','999999')";
	$db->query($sql);
	
	$sqlclass="select * from " . tname('newsclass') . " where CD_FatherID='".$CD_FatherID."' ";
	$results=$db->query($sqlclass);
	if($results) {
	while($row3=$db->fetch_array($results)) {
		$CD_TieID.=$row3["CD_ID"].',';
		$a=$a+1;
	}
	}
	$CD_TieID=rtrim($CD_TieID, ',');
	$db->query('update ' . tname('newsclass') . " set CD_TieID='".$CD_TieID."' where CD_ID='".$CD_FatherID."'");
	$db->query('update ' . tname('newsclass') . " set CD_TieID='".$CD_TieID."' where CD_ID in (".$CD_TieID.")");
	showmessage("恭喜您，添加栏目成功！", "newsclass.php", 0);
}

function EditSave() {
	global $db;
	$CD_ID=RequestBox("CD_ID");
	if($CD_ID=="0") {
		showmessage("出错了，请选择要编辑的栏目！", "newsclass.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");
			if(!IsNul($CD_Name)) {
				showmessage("出错了，栏目名称不能为空！", "newsclass.php", 1);
			}
			if(!IsNul($CD_AliasName)) {
				showmessage("出错了，英文别名不能为空！", "newsclass.php", 1);
			}
			if(!IsNul($CD_Template)) {
				showmessage("出错了，栏目模板不能为空！", "newsclass.php", 1);
			}
			if(!IsNum($CD_TheOrder)) {
				showmessage("出错了，排序不能为空！", "newsclass.php", 1);
			}
			$sql="update " . tname('newsclass') . " set CD_Name='" . $CD_Name . "',CD_AliasName='" . $CD_AliasName . "',CD_Template='" . $CD_Template . "',CD_TheOrder=" . $CD_TheOrder . " where CD_ID=" . $ID[$i] . "";
			$db->query($sql);
		}
		showmessage("恭喜您，编辑栏目成功！", "newsclass.php", 0);
	}

}

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

function delz() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "get");
	$CD_FID=SafeRequest("CD_FID", "get");
    $dj="select CD_ClassID from " . tname('news') . " where CD_ClassID='" . $CD_ID . "'";
    $djnum=$db->getrow($dj);
	if($djnum){showmessage("删除失败,请先转移分类下的数据！", "newsclass.php", 0);}
	$db->query("delete from " . tname('newsclass') . " where CD_ID='" . $CD_ID . "'");
	$sqlclass="select * from " . tname('newsclass') . " where CD_FatherID='".$CD_FID."' ";
	$results=$db->query($sqlclass);
	if($results) {
	while($row3=$db->fetch_array($results)) {
		$CD_TieID.=$row3["CD_ID"].',';
		$a=$a+1;
	}
	}
	$CD_TieID=rtrim($CD_TieID, ',');
	if($a>0){
		$db->query('update ' . tname('newsclass') . " set CD_TieID='".$CD_TieID."' where CD_ID='".$CD_FID."'");
	}else{
		$db->query('update ' . tname('newsclass') . " set CD_TieID='999999' where CD_ID='".$CD_FID."'");
	}
	$db->query('update ' . tname('newsclass') . " set CD_TieID='".$CD_TieID."' where CD_ID in (".$CD_TieID.")");
	die("<script>window.location='newsclass.php'</script>");

}

function del() {
	global $db;
	$CD_ID=SafeRequest("CD_ID", "get");
	$array=array('1');
	if(in_array($CD_ID, $array)) {
		showmessage("删除失败,系统自带栏目您只可以编辑不可删除。", "newsclass.php", 0);
	}
    $class="select CD_TieID from " . tname('newsclass') . " where CD_ID='" . $CD_ID . "'";
    $row=$db->getrow($class);
	if($row["CD_TieID"]!=="999999"){showmessage("删除失败,请先删除子分类模块！", "newsclass.php", 0);}
	
    $dj="select CD_ClassID from " . tname('newsc') . " where CD_ClassID='" . $CD_ID . "'";
    $djnum=$db->getrow($dj);
	if($djnum){showmessage("删除失败,请先转移分类下的数据！", "newsclass.php", 0);}

	$sql="delete from " . tname('newsclass') . " where CD_ID='" . $CD_ID . "'";
	if($db->query($sql)) {
		die("<script>window.location='newsclass.php'</script>");
	}
}
?>