<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "admin_loginstate.php";
include "../include/conn.php";
include "../include/function.php";
include "admin_version.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>视频专题管理</title>
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script src="js/jquery.js" language="javascript"></script>
<script src="js/Function.JS" language="javascript"></script>
<script language="javascript" src="js/topic.js"></script>
<script language="javascript" src="js/alerts.js"></script>
<link type="text/css" href="images/alerts.css" rel="stylesheet" media="screen">
<script language="javascript">
<!--
$(document).ready(function(){
	$("#button").click(function(){
		var TopicName=$("#TopicName").val();
		var Template=$("#Template").val();
		var Cname=$("#Cname").val();
		var re = /^[a-z0-9]*$/gi
	$("#TopicName").css("border-color","#666 #ccc #ccc #666");
	$("#Template").css("border-color","#666 #ccc #ccc #666");
	$("#Cname").css("border-color","#666 #ccc #ccc #666");
	$("#topname").text("");
	$("#stemplate").text("");
	$("#scname").text("");
		if(TopicName==""){
		$("#TopicName").css("border","1px solid red");
		$("#topname").text("请填写专题名称！").css("color","red");
		$("#TopicName").focus();
		jAlert("请填写专题名称！","操作提示");
		return false;
		}
		else if(Template==""){
		$("#Template").css("border","1px solid red");
		$("#stemplate").text("请指定专题模板文件！").css("color","red");
		$("#Template").focus();
		jAlert("请指定专题模板文件！","操作提示");
		return false;
		}
		else if(Cname==""){
		$("#Cname").css("border","1px solid red");
		$("#scname").text("请填写专题别名！").css("color","red");
		$("#Cname").focus();
		jAlert("请填写专题别名！","操作提示");
		return false;}	
		else if(re.test(Cname)==false){
		$("#Cname").css("border","1px solid red");
		jAlert("英文别名必须是数字或字母组成！","操作提示");
		return false;}
	})
$("#btn_spanall").click(function(){
		jConfirm('您确定要生成选中的专题吗！', '操作提示', function(r) {
				if(r==true){
					form1.action='?action=span';
					form1.submit();
					}
				});
	 })
	
$("#btn_delall").click(function(){
		jConfirm('您确定删除选中的视频专题吗?', '操作提示', function(r) {
				if(r==true){
					form1.action='?action=delall';
					form1.submit();
					}
				});
	 })	
	
	
})

function del(id){
	jConfirm('您确定删除该视频专题吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
		
		}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<link  href="images/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
	class ui_topic{
		public function editdata($Arr,$url){
						$name=$Arr[0];
						$color=$Arr[1];
						$aname=$Arr[2];
						$temp=$Arr[3];
						$pic=$Arr[4];
						$reco=$Arr[5];
						$hits=$Arr[6];
						$hide=$Arr[7];
						$key=$Arr[8];
						$remark=$Arr[9];
						$content=$Arr[10];		
			//图片保存路径session
			$_SESSION['imgtypes']="topic";
			if(IsNul($name)){
				$actionname="编辑";
				}
			else{
				$actionname="添加";
				}	

?>
<script charset="utf-8" src="edit/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="edit/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript">
KindEditor.ready(function(K) {
	K.create('#S_Content', {
		resizeType : 2,
		allowPreviewEmoticons : false,
		uploadJson: 'edit/upload.kindeditor.php',
		formatUploadUrl : false,
		allowFileManager : false,
		fillDescAfterUploadImage : true,
		//allowImageUpload : true,
		items : [
			'source', ,'|', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'image', 'link', 'unlink'],
		extraFileUploadParams : {
			module : 'zt',
			type : 'pic'
		},
		afterChange : function() {
			K('#str_count').html(this.count());
		}
	});
	
	K.ctrl(document.body, 'Z', function() {
		document.forms['form1'].submit();
	});
	//取色器开始
	var colorpicker;
	var colorpickerid = K('#colorpicker');
	colorpickerid.bind('click', function(e) {
		e.stopPropagation();
		if (colorpicker) {
			colorpicker.remove();
			colorpicker = null;
			return;
		}
		var colorpickerPos = colorpickerid.pos();
		colorpicker = K.colorpicker({
			colors : [["#FF0000","#E56600","#FF9900","#64451D","#DFC5A4","#FFE500"],["#009900","#006600","#99BB00","#B8D100","#60D978","#00D5FF"],["#337FE5","#003399","#4C33E5","#9933E5","#CC33E5","#EE33EE"],["#FFFFFF","#CCCCCC","#999999","#666666","#333333","#000000"]],
			x : colorpickerPos.x,
			y : colorpickerPos.y + colorpickerid.height(),
			z : 19811214,
			selectedColor : 'default',
			noColor : '无颜色',
			click : function(color) {
				colorpickerid.val(color);
				colorpicker.remove();
				colorpicker = null;
			}
		});
	});
	K(document).click(function() {
		if (colorpicker) {
			colorpicker.remove();
			colorpicker = null;
		}
	});
	//图片上传开始
	var editor = K.editor({
		uploadJson: 'edit/upload.kindeditor.php',
		formatUploadUrl : false,
		extraFileUploadParams : {
			module : 'zt',
			type : 'logo'
		}
	});
	K('#image3').click(function() {
		editor.loadPlugin('image', function() {
			editor.plugin.imageDialog({
				showRemote : false,
				imageUrl : K('#url3').val(),
				clickFn : function(url, title, width, height, border, align) {
					K('#url3').val(url);
					editor.hideDialog();
				}
			});
		});
	});
});
</script>

<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
					<form id="form1" name="form1" method="post" action="<?php echo $url?>">
                <table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
                    <tr>
                      <td class="td_title" colspan="2" >&nbsp;<?php echo $actionname?>视频专题</td>
                    </tr>
                	<tr>
<td width="85"   height="30" class="td_border">&nbsp;专题名称：</td>
                    <td width="666" class="td_border"><input type="text" name="TopicName" id="TopicName" value="<?php echo $name?>" size="35" />
                      <font color="#FF0000">＊</font>&nbsp; <label id="topname"></label> 
					  颜色：
					  <input type="text" name="S_Color" size="10" value="<?php echo $color;?>" id="colorpicker" />
					</td></tr>
                    <tr>
                      <td width="85" height="30" class="td_border">&nbsp;英文别名：</td>
                      <td class="td_border" >
<input type="text" name="Cname" id="Cname" value="<?php echo $aname?>" size="35" />
<font color="#FF0000">＊</font>&nbsp;&nbsp;&nbsp;<label id="scname"></label></td></tr>
                    <tr>
                      <td width="85" height="30" class="td_border">&nbsp;专题模板：</td>
                      <td class="td_border" >
                      <input type="text" name="Template" id="Template" <?php if(!IsNul($temp)){?> value="vodtopic.html"<?php }else{?>value="<?php echo $temp?>"<?php }?> size="35" />
                      <font color="#FF0000">＊</font><label id="stemplate"></label>
                      <input type="checkbox" name="edittime" class="checkbox" id="edittime"   value="1" checked="checked"/>
更新时间</td></tr>
                      <tr>
                        <td width="85" height="30" class="td_border">&nbsp;专题图片：</td>
						<td height="30" class="td_border">
						<input type="text" name="S_Pic" id="url3" value="<?php echo $pic?>" size="35" /> <input type="button" id="image3" value="选择图片" /></td>
                    </tr>

                    <tr>
                      <td width="85" height="30" class="td_border">&nbsp;推荐星级：</td>
                      <td class="td_border" ><select name="Reco" id="Reco" style=" color:#FF0000; " >
                          <option value="0" <?php if($reco==0){echo "selected";}?>>取消</option>
                          <option value="1" <?php if($reco==1){echo "selected";}?>>一星</option>
                          <option value="2" <?php if($reco==2){echo "selected";}?>>二星</option>
                          <option value="3" <?php if($reco==3){echo "selected";}?>>三星</option>
                          <option value="4" <?php if($reco==4){echo "selected";}?>>四星</option>
                          <option value="5" <?php if($reco==5){echo "selected";}?>>五星</option>
                        </select>
                     &nbsp; 人气:
                      <input type="text" name="Hits" id="Hits" value="<?php if(!IsNum($hits)){$hits=0;}?><?php echo $hits?>"  size="5" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>                      
                      &nbsp;&nbsp;是否隐藏：
                    <input type="radio" name="IsHide" id="IsHide"  checked value="0" class="radio" />显 示&nbsp;&nbsp;<input type="radio" name="IsHide" id="IsHide" <?php if($hide==1){echo "checked";}?> value="1"  class="radio"/>
                    隐 藏  <label id="shits"></label>                  </td></tr>
                    <tr>
                      <td width="85" height="30" class="td_border">&nbsp;专题标签：</td>
                      <td class="td_border" ><input type="text" name="keyword2" id="keyword2" value="<?php echo $key?>" size="50" />
                      <br />
                      <font color="#FF0000">＊ 注意：每个标签关健词可以使用&quot;逗号,空格,|,下划线,&quot;来隔开 </font></td>
                    </tr>
                    <tr>
                      <td height="30" class="td_border">&nbsp;专题概述：</td>
                      <td class="td_border" ><font color="#FF0000">
                        <textarea name="S_Remark"  id="S_Remark"cols="83" rows="3"><?php echo $remark?></textarea>
                      <br />
                      ＊不填写则自动截取专题介绍的前100个字符</font></td>
                    </tr>
                    <tr>
                      <td width="85" height="30" class="td_border">&nbsp;专题介绍：</td>
						<td class="td_border"><p></p>
						<textarea rows="15" cols="103" id="S_Content" name="S_Content"><?php echo $content;?></textarea>
						<p>您当前输入了<span id="str_count"></span>字符</p>
						</td></tr>
                    <tr><td height="50" colspan="2" align="center" class="td_border" ><input type="submit" name="button" id="button" value="确定提交" class="rb1"/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
<input type="reset" name="button2" id="button2" value="清除重设" class="rb1"/></td>
                    </tr>
                </table>
</form>
		</div>
	</div>
</div>
<?php			
			}
		
		public function main($sql,$size){
			global $db;
			$Arr=getpagerow($sql,$size);//sql,每页显示条数
			$result=$db->query($Arr[2]);
			$videotopicnum=$db->num_rows($result);
			$action=SafeRequest("action","get");
?>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
                <form id="form1" action="" method="post" name="form1">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
                     <tr>
                       <td colspan="8" class="td_title">&nbsp;视频专题列表</td>
                     </tr>
                     <tr>
                       <td height="40" colspan="8" class="td_border">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关键字：
                         <input name="keyword" type="text" id="keyword" value="" size="25" >
                         <input type="hidden" id="types" name="types" value="1">
                         <input type="button" id="search" value="搜索" class="rb1" >
&nbsp;&nbsp;&nbsp;&nbsp;
<select name="select"  onchange="MM_jumpMenu('self',this,0)">
  <option value="admin_video.asp">查看选项</option>
  <option value="?action=listbyreco">推荐星级</option>
  <option value="?action=listhide">隐藏专题</option>
  <option value="?action=listunhide">显示专题</option>
  <option value="?action=listtimeup">时间升序</option>
  <option value="?action=listtimedown">时间降序</option>
  <option value="?action=listidup">序号升序</option>
  <option value="?action=listiddown">序号降序</option>
  <option value="?action=listbyhits">人气升序</option>
  <option value="?action=listbyhitsa">人气降序</option>
</select></td>
                      </tr>
                      <tr>
                        <td width="10%" height="30" bgcolor="#FFFFFF"  class="td_btop3">&nbsp;&nbsp;编号
                     	<?php if($action=="listidup"){?>
                       			 <a href="?action=listiddown"><img src="images/down.gif" border="0" alt="点击按ID升序排列"></a>
                        <?php	}
							else{
						?>
								<a href="?action=listidup"><img src="images/up.gif" border="0" alt="点击按ID升序排列"></a>
						<?php		}?>                       
                        </td>
                        <td width="25%" height="30" bgcolor="#FFFFFF"  class="td_btop3">&nbsp;专题名称</td>
                        <td width="8%" align="center" bgcolor="#FFFFFF"  class="td_btop3">人气
                     	<?php if($action=="listbyhits"){?>
                        <a href="?action=listbyhitsa"><img src="images/up.gif" border="0" alt="点击按人气排序"></a>
                        <?php }else{?>
                         <a href="?action=listbyhits"><img src="images/down.gif" border="0" alt="点击按人气排序"></a>
                        <?php }?>                       
                        </td>
                        <td width="14%" align="center" bgcolor="#FFFFFF" class="td_btop3">英文别名</td>
                        <td width="13%"    align="center" bgcolor="#FFFFFF" class="td_btop3">推荐星级
                     <?php if($action=="listbyreco"){?>
                    	<a href="?action=listbyrecoa"><img src="images/up.gif" border="0" alt="点击按星级排序"></a>
                    <?php }else{?>
                    	<a href="?action=listbyreco"><img src="images/down.gif" border="0" alt="点击按星级排序"></a>
                    <?php }?>                       
                        </td>
                        <td width="13%"    align="center" bgcolor="#FFFFFF" class="td_btop3">更新时间
                     <?php if($action=="listbytime"){?>
                    	<a href="?action=listbytimea"><img src="images/up.gif" border="0" alt="点击按星级排序"></a>
                    <?php }else{?>
                    	<a href="?action=listbytime"><img src="images/down.gif" border="0" alt="点击按星级排序"></a>
                    <?php }?>                       
                        </td>
                        <td width="5%"   align="center" bgcolor="#FFFFFF" class="td_btop3">显示</td>
                        <td width="12%"   align="center" bgcolor="#FFFFFF" class="td_btop3">操作</td>
                      </tr>
                       <?php
					   if($videotopicnum==0) echo "
							<tr>
                            	<td colspan=\"8\" class=\"td_border\" height=\"30\" align=center><b>Sorry！暂无视频专题,请添加！</b></td>
                            </tr>";						   
                       if($result){
						   while ($row = $db ->fetch_array($result)){

					   ?> 
                       <tr>
                        <td width="8%" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="checkbox" id="S_ID" name="S_ID[]" value="<?php echo $row['S_ID']?>" class="checkbox">
                         <?php echo $row['S_ID']?>、</td>
                        <td width="25%" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;<font color="<?php echo $row['S_Color']?>"><?php echo $row['S_Name']?></font>&nbsp;<font color="#ff0000">(共<?php
           		$sqlstr="select * from s_video where S_Topic=".$row['S_ID']."";
        		$res=$db -> query($sqlstr);
 				$nums= $db -> num_rows($res);
				echo $nums;
						?>条)</font></a></td>
                        <td width="8%" height="30" align="center" bgcolor="#FFFFFF" class="td_border"><?php echo $row['S_Hits']?></td>
                        <td width="14%" height="30" align="center" bgcolor="#FFFFFF" class="td_border"><?php echo $row['S_AliasName']?></td>
                        <td width="13%" height="30" align="center" bgcolor="#FFFFFF" class="td_border"id="S_Reco<?php echo $row['S_ID']?>">&nbsp;
                         <script language="javascript">ShowStar(<?php echo $row['S_Reco']?>,<?php echo $row['S_ID']?>)</script></td>
                        
                        <td width="15%" height="30" align="center" bgcolor="#FFFFFF" class="td_border">
                        <?php 
								if(date("Y-m-d",strtotime($row['S_AddTime']))==date('Y-m-d')){
									echo "<font color=red>".date("Y-m-d",strtotime($row['S_AddTime']))."</font>";
									}
								else{
									echo date("Y-m-d",strtotime($row['S_AddTime']));
									}	
								?></td>
                        <td width="5%" height="30" align="center" bgcolor="#FFFFFF" class="td_border"><a href="?action=ishide&S_ID=<?php echo $row['S_ID']?>&S_IsHide=<?php echo $row['S_IsHide']?>"><?php if($row['S_IsHide']==0){echo "<img src='../images/common/yes.gif'/>";}else{echo "<img src='../images/common/no.gif'/>";}?></a></td>
                        <td width="12%" height="30" align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<a href="?action=editdata&S_ID=<?php echo $row['S_ID']?>">编辑</a> &nbsp;<a style="cursor:pointer;" onclick="del(<?php echo $row['S_ID']?>)">删除</a></td>
                      </tr>
                         <?php
							   }
					   }
					?> 
		
                  
                    <tr>
                        <td height="30" colspan="8" align="left" class="td_border" bgcolor="#FFFFFF">&nbsp;<input type="checkbox" value="" class="checkbox" id="ChkAll" name="ChkAll" />
                        全选&nbsp;&nbsp;&nbsp;&nbsp; <input type="button" value="删除删除专题" class="rb1" id="btn_delall"  >
                       &nbsp; &nbsp;<input type="button" name="button" value="批量生成" class="rb1"  id="btn_spanall" disabled="disabled"/>&nbsp; &nbsp;
                        <input type="button" value="增加新主题" onClick="location.href='?action=add'" class="rb1" /></td>
                      </tr>
                   <tr>
				    <td height="30" colspan="8" align="right" class="td_border"><?php echo $Arr[0];?></td>
			      </tr> 
                  </table> 
     </form>
		</div>
	</div>
</div>
<?php			
			}
		
		}
?>        

<?php
$ui=new ui_topic;
$action=SafeRequest("action","get");
switch($action){
	case 'main':
		$ui->main("select * from s_topic where S_SystemID=1",20);
		break;
	case 'add':
		add();
		break;
	case 'saveadd':
		saveadd();
		break;
	case 'editdata':
		editdata();
		break;
	case 'saveedit':
		saveedit();
		break;
	case 'del':
		del();
		break;
	case 'delall':
		delall();
		break;
	case 'listbysc':
		search();
		break;
	case 'listidup':
		listidup();
		break;
	case 'listbyhits':
		listbyhits();
		break;
	case 'listbyreco':
		listbyreco();
		break;
	case 'listbyrecoa':
		listbyrecoa();
		break;
	case 'listbytime':
		listbytime();
		break;
	case 'listbytimea':
		listbytimea();
		break;
	case 'ishide':
		ishide();
		break;
	default:
		$ui->main("select * from s_topic where S_SystemID=1 order by S_ID desc",20);
	}
	function ishide(){
		global $db;
		$ishide=SafeRequest("S_IsHide","get");
		$id=SafeRequest("S_ID","get");
		if(!IsNum($ishide)) $ishide=0;
		if(!IsNum($id)) die("<script>jAlert('id传输错误?','操作提示',function(R){history.back();})</script>");
		if($ishide==1){
			$ishide=0;
			}
		else{
			$ishide=1;
			}	
		$sql="update s_topic set S_IsHide=$ishide where S_ID=$id";
		if($db->query($sql)){
			die("<script>window.location='admin_videotopic.php';</script>");
			}
		else{
			die("<script>jAlert('未知错误!','操作提示',function(R){history.back();})</script>");
			}		
		}
		
	//时间
	function listbytime(){
		global $ui;
		$ui->main("select * from s_topic  where  S_SystemID=1 order by S_AddTime desc",30);				
		}
	function listbytimea(){
		global $ui;
		$ui->main("select * from s_topic  where S_SystemID=1 order by S_AddTime asc",30);				
		}	
	
	//星级
	function listbyreco(){
		global $ui;
		$ui->main("select * from s_topic  where  S_SystemID=1 order by S_Reco desc",30);		
		}
	function listbyrecoa(){
		global $ui;
		$ui->main("select * from s_topic  where S_SystemID=1 order by S_Reco asc",30);		
		}	
	//人气
	function listbyhits(){
		global $ui;
		$ui->main("select * from s_topic  where S_SystemID=1 order by S_Hits desc",30);
		}
	function listbyhitsa(){
		global $ui;
		$ui->main("select * from s_topic where  S_SystemID=1 order by S_Hits asc",30);		
		}	
	//id升序
	function listidup(){
		global $ui;
		$ui->main("select * from s_topic   where S_SystemID=1 order by S_ID asc",30);
		}

	function search(){
		global $ui;
		$key=SafeRequest("keyword","get");
		$sql="select * from s_topic where S_SystemID=1 and S_Name like '%".$key."%'";
		$ui->main($sql,20);
		}
	
	function delall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		$sql="delete from s_topic where S_ID in ($S_ID)";
		if($S_ID=="0"){
			die("<script>jAlert('请选择要删除的专题?','操作提示',function(R){history.back();})</script>");
			}
		else{
			if($db->query($sql)){
				die("<script>jAlert('恭喜你！操作成功了！','成功提示',function(R){window.location='admin_videotopic.php';})</script>");
				}
			else{
				die("<script>jAlert('专题删除失败','操作提示',function(R){window.location='admin_videotopic.php';})</script>");
				}	
			}
		}
	
	function del(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$sql="delete from s_topic where S_ID='".$S_ID."'";
		if($db->query($sql)){
			echo "<script>window.location='admin_videotopic.php'</script>";
			}
		else{
			die("<script>jAlert('专题删除失败','操作提示',function(R){window.location='admin_videotopic.php';})</script>");
			}	
		}
	
	function saveedit(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$TopicName = SafeRequest("TopicName","post");
		$Template = SafeRequest("Template","post");
		$Cname = SafeRequest("Cname","post");
		$S_Pic = SafeRequest("S_Pic","post");
		$S_Content = SafeRequest("S_Content","post");
		$IsHide = SafeRequest("IsHide","post");
		$Color=SafeRequest("S_Color","post");
		$Keyword=SafeRequest("keyword2","post");
		$Hits = SafeRequest("Hits","post");
		if(!IsNum($Hits)){$Hits==0;}
		$Reco= SafeRequest("Reco","post");
		$S_Remark = SafeRequest("S_Remark","post");
		$S_AddTime =date("Y-m-d");
		if(!IsNul($S_Remark)) $S_Remark=substr(strip_tags($S_Content),0,100);

		$sql="update s_topic set S_Name='".$TopicName."',S_Keywords='".$Keyword."',S_Color='".$Color."',S_AliasName='".$Cname."',S_Pic='".$S_Pic."',S_Template='".$Template."',S_Remark='".$S_Remark."',S_Content='".$S_Content."',S_Reco=".$Reco.",S_IsHide=".$IsHide.",S_Hits=".$Hits.",S_AddTime='".$S_AddTime."' where S_ID=".$S_ID."";
		if($db->query($sql)){
			echo "<script>window.location='admin_videotopic.php'</script>";
			}
		else{
			die("<script>jAlert('专题编辑失败','操作提示',function(R){window.location='admin_videotopic.php';})</script>");
			}	
		}
	
	function editdata(){
		global $ui;
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$sql="Select * from s_topic where S_ID=".$S_ID."";
		if($row=$db->Getrow($sql)){
			$Arr=array($row['S_Name'],$row['S_Color'],$row['S_AliasName'],$row['S_Template'],$row['S_Pic'],$row['S_Reco'],$row['S_Hits'],$row['S_IsHide'],$row['S_Keywords'],$row['S_Remark'],$row['S_Content']);
			}
		$ui->editdata($Arr,"?action=saveedit&S_ID=".$S_ID."");

		}
	
	function add(){
		global $ui;
		$Arr=array("","","","","","","",0,"","","","");
		$ui->editdata($Arr,"?action=saveadd");
		}
	function saveadd(){
		global $db;
		$TopicName = SafeRequest("TopicName","post");
		$Template = SafeRequest("Template","post");
		$Cname = SafeRequest("Cname","post");
		$S_Pic = SafeRequest("S_Pic","post");
		$S_Content = SafeRequest("S_Content","post");
		$IsHide = SafeRequest("IsHide","post");
		$Color=SafeRequest("S_Color","post");
		$Keyword=SafeRequest("keyword2","post");
		$Hits = SafeRequest("Hits","post");
		if(!IsNum($Hits)){$Hits==0;}
		$Reco= SafeRequest("Reco","post");
		$S_Remark = SafeRequest("S_Remark","post");
		$S_AddTime =date("Y-m-d");
		if(!IsNul($S_Remark)) $S_Remark=substr(strip_tags($S_Content),0,100);
		$sql="Insert s_topic  (S_Name,S_Keywords,S_Color,S_AliasName,S_Pic,S_Template,S_Remark,S_Content,S_Reco,S_IsHide,S_SystemID,S_Hits,S_AddTime) values ('".$TopicName."','".$Keyword."','".$Color."','".$Cname."','".$S_Pic."','".$Template."','".$S_Remark."','".$S_Content."',".$Reco.",".$IsHide.",1,".$Hits.",'".$S_AddTime."')";

		if($db->query($sql)){
			echo "<script>window.location='admin_videotopic.php'</script>";
			}
		else{
			die("<script>jAlert('专题添加失败','操作提示',function(R){window.location='admin_videotopic.php';})</script>");
			}	
		}	
?>
<?php include "admin_bottom.php"; ?>
</body>
</html>