<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../include/conn.php";
include "../include/function.php";
include "admin_version.php";
include "admin_loginstate.php";
include "../include/userset.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>
<link  href="images/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/news.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(){
	$("#addnew").click(function(){
	var S_Name=$("#S_Name").val();
	var S_ClassID=$("#S_ClassID").val();
	$("#S_Name").css("border-color","#666 #ccc #ccc #666");
	$("#sClassID").text("");
	if(S_Name==""){
		$("#S_Name").css("border","1px solid red");
		$("#sClassID").text("请填写文章标题！").css("color","red");
		$("#S_Name").focus();
		$("#S_Name").select();
		jAlert("请填写文章标题！","操作提示");
		return false;
		}
	else if(S_ClassID=="0"){
		$("#sClassID").text("请选择文章分类！").css("color","red");
		$("#S_Name").focus();
		jAlert("请选择文章分类！","操作提示");
		return false;
		}

	})	
	
	$("#showvideo1").click(function (){
	window.location='admin_article.php?action=listbylz&types=dellist';
	});
	$("#showvideo2").click(function(){
	window.location='admin_article.php?action=listbylz';
	});
	$("#showvideo3").click(function (){
	window.location='admin_article.php?action=listbylz&types=unclass';
	});
	$("#S_IsEnd").click(function(){
			var remark=$("#remarkbak").val();				 
			if($(this).attr("checked")==true){
				if(remark==""){
					$("#S_Remark").val("完结");
				}
				else{
					$("#S_Remark").val(remark);
					}
			}
			else{
				$("#S_Remark").val("全集");
				}

		 });
	
	$("#btn_editall").click(function(){
		jConfirm('您确定要执行操作吗?', '操作提示', function(r) {
				if(r==true){formb.submit();}
				});
	 });
	
	$("#delallsel4").click(function(){
		$("#ClassIDs").show();
		$("#TopicID").hide();
		$("#deltypes").hide();
	})
	
	$("#delallsel5").click(function(){
		$("#ClassIDs").hide();
		$("#TopicID").show();
		$("#deltypes").hide();
	})
	
	$("#delallsel1").click(function(){
		$("#ClassIDs").hide();
		$("#TopicID").hide();
		$("#deltypes").show();
	})
	
	$("#delallsel6").click(function(){
		$("#ClassIDs").hide();
		$("#TopicID").hide();
		$("#deltypes").hide();
	})
	
});

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;
}

function chgclass(id,cid){
	$.get("js/ajaxfun.php?action=chgclasslist&id="+id+"&cid="+cid+"&sid=2",function(R){
			$("#class_"+id).html(R);												
			})
	}
	
function savechgclass(cid,id){
	$.get("js/ajaxfun.php?action=savecls&id="+id+"&cid="+cid+"&sid=2",function(R){
				$("#class_"+id).html(R);													  
			});
	}
</script>

</head>

<body>
<?php
SystemPer(3);
	class ui_video{
		
		public function editdata($Arr,$url){
			global $editor;
			global $db;
			$editor->BasePath='edit';
			$editor->Height=465;
			$editor->Width=650;
			$editor->AutoSave=false;
						$name=$Arr[0];
						$color=$Arr[1];
						$classid=$Arr[2];
						$topic=$Arr[3];
						$pic=$Arr[4];
						$author=$Arr[5];
						$content=$Arr[6];
						$reco=$Arr[7];
						$source=$Arr[8];
						$hits=$Arr[9];
						$key=$Arr[10];
						$remark=$Arr[11];
			$editor->Value=	$content;		
			//图片保存路径session
			$_SESSION['imgtypes']="article";
?>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
         				<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">	
							<form action="<?php echo $url?>" method="post"  name="form1" >
							  
							  <tr>
                                <td colspan="2" class="td_title">&nbsp;文章信息编辑</td>
                              </tr>
                              
							  <tr>
								<td width="12%" height="30" class="td_border">&nbsp;文章标题：</td>
								<td width="88%"  height="30" class="td_border"><input type="text" name="S_Name" id="S_Name" value="<?php echo $name?>" size="35" />
								  <font color="#FF0000">＊</font>
                                  颜色：
<select name="S_Color" >
  <?php if(!IsNul($color)){?>
  <option  value=""></option>
  <?php }else{?>
  <option style="background-color:<?php echo $color?>;color: <?php echo $color?>" value="<?php echo $color?>"></option>
  <?php }?>
  <option style="background-color:#00FF00;color: #00FF00" value="#00FF00">绿色</option>
  <option style="background-color:#0000CC;color: #0000CC" value="#0000CC">深蓝</option>
  <option style="background-color:#FFFF00;color: #FFFF00" value="#FFFF00">黄色</option>
  <option style="background-color:#FF33CC;color: #FF33CC" value="#FF33CC">粉红</option>
  <option style="background-color:#FF0000;color: #FF0000" value="#FF0000">红色</option>
  <option style="background-color:#660099;color: #660099" value="#660099">紫色</option>
  <option style="background-color:#FFFFFF;color: #FFFFFF" value="">无色</option>									
</select>                                    &nbsp;&nbsp;文章分类：
	<select name="S_ClassID" id="S_ClassID">
              <?php
              	$sqlclass="select * from s_class where S_SystemID=2 ";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
						if($classid==$row3['S_ID']){
							echo "<option value='".$row3['S_ID']."' selected='selected'>".$row3['S_Name']."</option>";
							}
						else{
							echo "<option value='".$row3['S_ID']."' >".$row3['S_Name']."</option>";
							}	
						
						}
					}
			  ?>	 
		 </select>
<font color="#FF0000">＊</font><label id="sClassID"></label></td>
							  </tr>
							  <tr>
								<td height="30" class="td_border"> &nbsp;文章作者：</td>
								<td height="30" class="td_border"><input name="S_Author" type="text" id="S_Author" value="<?php echo $author?>" size="35"  />
								  <input type="checkbox" class="checkbox" name="addtime" value="checkbox" checked="checked"/>
更新时间</td>
							  </tr>
							  <tr>
							    <td height="30" class="td_border">&nbsp;文章来源：</td>
							    <td height="30" class="td_border"><input name="S_Source" type="text" id="S_Source" value="<?php echo $source?>" size="35" /></td>
						      </tr>
							  <tr>
                              <td height="30" class="td_border">&nbsp;文章图片：</td>
								<td height="30" class="td_border">
                                  <input name="S_Pic" type="text" id="S_Pic" value="<?php echo $pic?>" size="35" />
                                  <input name="doclear" type="button" class="rb1" id="doclear" value="清  除" onclick="javascript:document.form1.S_Pic.value='';"/>
                                <iframe src="js/upload.php?action=article" scrolling="No" topmargin="0" width="300" height="30" marginwidth="0" marginheight="0" frameborder="0" align="center"></iframe></td>
							  </tr>
							  <tr>
                              <td height="30" class="td_border">&nbsp;推荐星级：</td>
							    <td height="30" class="td_border">
<select name="S_Reco" id="S_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;&nbsp;&nbsp;文章人气：
<input type="text" name="S_Hits" id="S_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,''))"/></td>
							  </tr>
						
							  <tr>
								<td height="30" class="td_border">&nbsp;所属专题：</td>
								<td height="30" class="td_border">
                                <input type="hidden" name="VideoRightID" value="0" />
								<select name="S_Topic" id="S_Topic">
                                	<option value="0">选择新闻专题</option>
              <?php
              	$sqlclass="select * from s_topic where S_SystemID=2 ";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
						if($topic==$row3['S_ID']){
							echo "<option value='".$row3['S_ID']."' selected='selected'>".$row3['S_Name']."</option>";
							}
						else{
							echo "<option value='".$row3['S_ID']."' >".$row3['S_Name']."</option>";
							}	
						
						}
					}
			  
			  ?>
								</select></td>
							  </tr>
							  <tr>
							    <td height="30" class="td_border">&nbsp;文章标签：</td>
							    <td height="30" class="td_border"><font color="#FF0000">
							      <input name="S_Keywords" type="text" id="S_Keywords" value="<?php echo $key?>" size="50" />
							      <br />
						        ＊ 注意：每个标签关健词可以使用&quot;逗号,空格,|,下划线,&quot;来隔开							    </font></td>
						      </tr>
							  <tr>
								<td height="30" class="td_border">&nbsp;文章概述：</td>
								<td height="30" class="td_border"><textarea name="S_Remark" id="S_Remark" cols="83" rows="3"><?php echo $remark?></textarea>
							    <font color="#FF0000"><br />
							     不填写则自动截取文章内容的前100个字</font></td>
							  </tr>

						
							  <tr>
                               <td class="td_border">&nbsp;&nbsp;文章内容：</td>
								<td class="td_border">
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                                <tr>
								<td  class="td_border">						
						<?php
                      	$editor->Create();
					  ?></td>
                                </tr>
                                </table>  </td>
							  </tr>
							  
							  <tr>
								<td height="30" class="td_border"></td>
								<td class="td_border" align="center" height="40"> &nbsp;
								  <input type="submit" name="Submit" value="确定提交"class="rb1"  id="addnew"/>
								  &nbsp;&nbsp; <input type="reset" name="reset" value="清除重置" class="rb1"/></td>
							  </tr>
							</form>  
					  </table>
           </div>
	</div>
</div>   

<?php			
			}
		
		function main($sql,$size){
			global $db;
			$Arr=getpagerow($sql,$size);//sql,每页显示条数
			$result=$db->query($Arr[2]);
			$articlenum=$db->num_rows($result);
			$action=SafeRequest("action","get");
?>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
          <form name="form1" id="form1" method="post">

            <table class="tb_style" border="0"  cellspacing="0" cellpadding="0" >
                <tr>
                  <td class="td_title">&nbsp;文章数据管理&nbsp;[共有<span id="vpicnum" style="color:red;"><img src="images/loading2.gif"><script language="javascript">$.get("js/ajaxfun.php?action=getpicnum&sid=2",function(R){$("#vpicnum").html(R);})</script></span>张远程图片]&nbsp;&nbsp;[<a href="admin_downpic.php?sid=2"><font color="#FF0000">保存到本地</font></a>]</td>
                </tr>
              </table>
    				 <table class="tb_style" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="30" width="70">&nbsp; 关键字:</td>
                      <td align="center" width="150">&nbsp;<input name="keyword" type="text" id="keyword" value="" /></td>
                      <td align="center" width="70">&nbsp;<input name="搜索" type="button" id="search" value="搜索" class="rb1"/></td>
                      <td>&nbsp;

                      <select  onchange="MM_jumpMenu('self',this,0)">
                             <option value="admin_article.php">查看分类</option>
             <?php
              	$sqlclass="select * from s_class where S_SystemID=2 ";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
					echo "<option value='?action=listbycs&S_ID=".$row3['S_ID']."' >".$row3['S_Name']."</option>";
						}
					}
			  
			  ?>             
                      </select>
                       &nbsp;&nbsp;&nbsp;
                       <select  onchange="MM_jumpMenu('self',this,0)">
                            <option value="admin_article.php">查看专题</option>
              <?php
              	$sqlclass="select * from s_topic where S_SystemID=2 ";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
					echo "<option value='?action=listbytopic&S_ID=".$row3['S_ID']."' >".$row3['S_Name']."</option>";
						}
					}
			  
			  ?>	
            </select>
                       &nbsp;
</td>
                      </tr>
                  </table>
                    </form>

				<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style" >
				  <form method="post" name="formb" action="?action=delall" >
				  <tr>
					<td width="89" height="30" bgcolor="#FFFFFF" class="td_btop3">&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="300"  align="center" bgcolor="#FFFFFF" class="td_btop3">文章标题</td>
					<td width="77" 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="96" align="center" bgcolor="#FFFFFF" class="td_btop3">文章分类</td>
					<td width="84" align="center" bgcolor="#FFFFFF" class="td_btop3">专题</td>
					<td width="114"  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="110" 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 colspan="2" align="center" bgcolor="#FFFFFF" class="td_btop3">操 作</td>
				  </tr>
                       <?php
						if($articlenum==0) echo "
							<tr>
                            	<td colspan=\"8\" class=\"td_border\" height=\"30\" align=center><b>暂无文章,请添加</b></td>
                            </tr>";
						if($result){
						   while ($row = $db ->fetch_array($result)){
					   ?>  
							<tr>
							  <td height="30" class="td_border" width="89">&nbsp;
						      <input type="checkbox" name="S_ID[]" value="<?php echo $row['S_ID']?>" class="checkbox" id="S_ID"/><?php echo $row['S_ID']?>、</td>
								<td width="300" align="left" class="td_border">
  								<a href="<?php echo LinkUrl("s_article",$row['S_ClassID'],1,$row['S_ID'])?>" target="_blank"><font color="<?php echo $row['S_Color']?>"><?php echo $row['S_Name']?></font></a>
                                <?php if($action!="listdel"){?>
								<?php echo SpanShow("s_article",$row['S_ClassID'],1,$row['S_ID'],"mark/admin_spanarticleshow.php?sel=single")?>
                                <?php }?>                                </td>
								<td width="77" align="center" class="td_border"><?php echo $row['S_Hits']?></td>
                                <td width="96" align="center" class="td_border">
                                 <span id="class_<?php echo $row['S_ID']?>">
								<?php
                                	$res=$db->getrow("select S_Name from s_class where S_ID=".$row['S_ClassID']."");
									if($res){
										echo $res['S_Name'];
										}
									else{
										echo "暂无分类!";
										}	
								?><img src="images/edit.gif" onclick="chgclass(<?php echo $row['S_ID']?>,<?php echo $row['S_ClassID']?>)" style="cursor:pointer"></span>								</td>
								<td width="84" align="center" class="td_border"><div id="ss<?php echo $row['S_ID']?>"><span id="topicsel" s_id="<?php echo $row['S_ID']?>" topicid="<?php echo $row['S_Topic']?>" style="cursor:hand;">&nbsp;
							  <?php
                                	if($row['S_Topic']!=0){
										echo "<img src='images/topicyes.gif'>";
										}
									else{
										echo "<img src='images/topicno.gif'>";
										}	
								?></span></div></td>
							  <td width="114" align="center" class="td_border" id="S_Reco<?php echo $row['S_ID']?>"><script language="javascript">ShowStar(<?php echo $row['S_Reco']?>,<?php echo $row['S_ID']?>)</script></td>
								<td width="110" align="center" class="td_border">&nbsp;<?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="33" align="center"  class="td_border"><A href="?action=editdata&S_ID=<?php echo $row['S_ID']?>">编辑</a></td>
                                <td width="37" align="center"  class="td_border"><a style="cursor:pointer;" onclick="del(<?php echo $row['S_ID']?>)" >删除</a></td>
							</tr>
   <?php
                         							   
		 }
	 }
?> 
				  <tr>
					<td height="30" colspan="11" align="left" class="td_border">&nbsp;<input type="checkbox" name="ChkAll" id="ChkAll" ids="S_ID"  class="checkbox"/>
全选
 &nbsp;&nbsp;
 <input type="radio" name="DelALLSel" id="delallsel1" checked="checked" class="radio" value="1">
 批量删除
 <select class="select" name="deltypes" id="deltypes">
 <?php if($action=="listdel"){?>
 	<option  value="2">还原数据</option>
 <?php }
 else{?>
   	<option  value="3">放入回收站</option>
 <?php }?> 
    <option value="6">直接删除</option>
 </select>
 <input type="radio" name="DelALLSel" id="delallsel4" value="4" class="radio"/>
批量分类
<select name="ClassIDs" id="ClassIDs" style="display:none;">
              <?php
              	$sqlclass="select * from s_class where S_SystemID=2 ";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
					echo "<option value='".$row3['S_ID']."' >".$row3['S_Name']."</option>";
						}
					}
			  
			  ?>	
</select>
<input type="radio" name="DelALLSel" id="delallsel5"  value="5" class="radio"/>
批量专题
<select name="TopicID" id="TopicID" style="display:none;">
              <?php
              	$sqlclass="select * from s_topic where S_SystemID=2 ";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
					echo "<option value='".$row3['S_ID']."' >".$row3['S_Name']."</option>";
						}
					}
			  
			  ?>	
</select>
<?php if(S_Webmode==0 and $action<>"listdel"){?>
<input type="radio" name="DelALLSel" id="delallsel6"  value="6" class="radio"/>
批量生成&nbsp;&nbsp;
<?php }?>
<input type="button" name="submit1" value="执行操作"  class="rb1" id="btn_editall"/>
<input id="showlist" name="showlist" type="text" value="" style="visibility:hidden"/>
&nbsp;</td>
				    </tr>
				  </form>
			  	  <tr>
				    <td height="30" colspan="11" align="right" class="td_border"><?php echo $Arr[0];?></td>
			      </tr>
			  </table>
         </div>
	</div>
</div>
<?php			
			}
		}

?>        

<?php
$ui=new ui_video;
$action=SafeRequest("action","get");
include_once('../images/edit/sinaEditor.class.php');
$editor=new sinaEditor('gently_editor');
switch($action){
	case 'main':
		$ui->main("select * from s_article where S_IsHide=0",20);
		break;
	case 'delall':
		delall();
		break;
	case 'del':
		del();
		break;
	case 'listdel':
		listdel();
		break;
	case 'listbysc':
		search();
		break;
	case 'add':
		add();
		break;
	case 'saveadd':
		saveadd();
		break;
	case 'editdata':
		editdata();
		break;
	case 'saveedit':
		saveedit();
		break;
	case 'listbycs':
		listbycs();
		break;
	case 'listbytopic':
		listbytopic();
		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;		
	default:
		$ui->main("select * from s_article  where S_IsHide=0 order by S_ID desc",20);
		break;
	}

	//时间
	function listbytime(){
		global $ui;
		$ui->main("select * from s_article  where  S_IsHide=0 order by S_AddTime desc",30);				
		}
	function listbytimea(){
		global $ui;
		$ui->main("select * from s_article  where S_IsHide=0 order by S_AddTime asc",30);				
		}	
	
	//星级
	function listbyreco(){
		global $ui;
		$ui->main("select * from s_article  where S_IsHide=0 order by S_Reco desc",30);		
		}
	function listbyrecoa(){
		global $ui;
		$ui->main("select * from s_article  where  S_IsHide=0 order by S_Reco asc",30);		
		}	
	//人气
	function listbyhits(){
		global $ui;
		$ui->main("select * from s_article  where  S_IsHide=0 order by S_Hits desc",30);
		}
	function listbyhitsa(){
		global $ui;
		$ui->main("select * from s_article  where   S_IsHide=0 order by S_Hits asc",30);		
		}	
	//id升序
	function listidup(){
		global $ui;
		$ui->main("select * from s_article  where  S_IsHide=0 order by S_ID asc",30);
		}


	//查询专题
	function listbytopic(){
		global $ui;
		$S_ID=SafeRequest("S_ID","get");
		$ui->main("select * from s_article where S_Topic=".$S_ID."",20);
		}
	
	//查询分类
	function listbycs(){
		global $ui;
		$S_ID=SafeRequest("S_ID","get");
		$ui->main("select * from s_article where S_ClassID=".$S_ID."",20);
		}
	
	function del(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$sql="delete from s_article where S_ID='".$S_ID."'";
		//die($sql);
		if($db->query($sql)){
			echo "<script>window.location='admin_article.php';</script>";
			}
		else{
			die("<script>jAlert('新闻删除失败','操作提示',function(R){window.location='admin_article.php';})</script>");
			}	
		}
	
	function saveedit(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$S_Name = SafeRequest("S_Name","post");
		$S_Color = SafeRequest("S_Color","post");
		$S_Remark = SafeRequest("S_Remark","post");
		$S_ClassID = SafeRequest("S_ClassID","post");
		$S_Topic = SafeRequest("S_Topic","post");
		$S_Pic = SafeRequest("S_Pic","post");
		$S_Author = SafeRequest("S_Author","post");
		$S_ConTent = SafeRequest("gently_editor","post");
		$S_ConTent1 = SafeRequest("gently_editor","post");
		$S_Reco = SafeRequest("S_Reco","post");
		$S_Source = SafeRequest("S_Source","post");
		$S_IsHide = SafeRequest("S_IsHide","post");
		$S_Hits = SafeRequest("S_Hits","post");
		$S_AddTime = SafeRequest("S_AddTime","post");
		$S_Remark = SafeRequest("S_Remark","post");
		if(!IsNul($S_Remark)) $S_Remark=cnsubstr($S_ConTent,200);
		$S_Keywords1 = SafeRequest("S_Keywords","post");
		$S_AddTime=date('Y-m-d H:i:s');
		$sql="update s_article set S_Name='".$S_Name."',S_Color='".$S_Color."',S_Remark='".$S_Remark."',S_ClassID=".$S_ClassID.",S_Topic=".$S_Topic.",S_Pic='".$S_Pic."',S_Author='".$S_Author."',S_Content='".$S_ConTent."',S_Reco=".$S_Reco.",S_Source='".$S_Source."',S_IsHide=0,S_Hits=".$S_Hits.",S_Keywords='".$S_Keywords1."',S_AddTime='".$S_AddTime."' where S_ID=".$S_ID."";
		if($db->query($sql)){
			echo "<script>window.location='admin_article.php';</script>";
			}
		else{
			die("<script>jAlert('编辑新闻失败','操作提示',function(R){history.back();})</script>");
			}	
		}
		
	function editdata(){
		global $ui;
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$sql="Select * from s_article where S_ID=".$S_ID."";
		if($row=$db->Getrow($sql)){
			$Arr=array($row['S_Name'],$row['S_Color'],$row['S_ClassID'],$row['S_Topic'],$row['S_Pic'],$row['S_Author'],$row['S_Content'],$row['S_Reco'],$row['S_Source'],$row['S_Hits'],$row['S_Keywords'],$row['S_Remark']);
			}
		$ui->editdata($Arr,"?action=saveedit&S_ID=".$S_ID."");
		
		}
	//执行添加
	function saveadd(){
		global $db;
		$S_Name = SafeRequest("S_Name","post");
		$S_Color = SafeRequest("S_Color","post");
		$S_Remark = SafeRequest("S_Remark","post");
		$S_ClassID = SafeRequest("S_ClassID","post");
		$S_Topic = SafeRequest("S_Topic","post");
		$S_Pic = SafeRequest("S_Pic","post");
		$S_Author = SafeRequest("S_Author","post");
		$S_ConTent = SafeRequest("gently_editor","post");
		$S_ConTent1 = SafeRequest("gently_editor","post");
		$S_Reco = SafeRequest("S_Reco","post");
		$S_Source = SafeRequest("S_Source","post");
		$S_IsHide = SafeRequest("S_IsHide","post");
		$S_Hits = SafeRequest("S_Hits","post");
		$S_AddTime = SafeRequest("S_AddTime","post");
		$S_Remark = SafeRequest("S_Remark","post");
		if(!IsNul($S_Remark)) $S_Remark=cnsubstr($S_ConTent,200);
		$S_Keywords1 = SafeRequest("S_Keywords","post");
		$S_AddTime=date('Y-m-d H:i:s');
		$sql="Insert s_article (S_Name,S_Color,S_Remark,S_ClassID,S_Topic,S_Pic,S_Author,S_Content,S_Reco,S_Source,S_IsHide,S_Hits,S_Keywords,S_AddTime) values ('".$S_Name."','".$S_Color."','".$S_Remark."',".$S_ClassID.",".$S_Topic.",'".$S_Pic."','".$S_Author."','".$S_ConTent."',".$S_Reco.",'".$S_Source."',0,".$S_Hits.",'".$S_Keywords1."','".$S_AddTime."')";
		//die($sql);
		if($db->query($sql)){
			echo "<script>window.location='admin_article.php';</script>";
			}
		else{
			die("<script>jAlert('添加新闻失败哦','操作提示',function(R){history.back();})</script>");
			}	

		}
	
	// 添加文章
	function add(){
		global $ui;
		$Arr=array("","","","","","","","","","","","");
		$ui->editdata($Arr,"?action=saveadd");
		}
	
	//搜索
	function search(){
		global $ui;
		$key=SafeRequest("keyword","get");
		$sql="select * from s_article where  S_Name like '%".$key."%'";
		$ui->main($sql,20);
		}
		
	//回收站
	function listdel(){
		global $ui;
		$ui->main("select * from s_article  where S_IsHide=1",20);
		}
	
	function delall(){
		global $db;
		$showlist=SafeRequest("showlist","post");
		$S_ID=RequestBox("S_ID");
		$S_ID1=RequestBox("S_ID");
		$DelALLSel=SafeRequest("DelALLSel","post");
		if($S_ID=="0"){
			echo "<script>jAlert('请选择要操作的数据?','操作提示',function(R){history.back();})</script>";
			die();
			}
		$Arr=explode(',',$S_ID);
		switch($DelALLSel){
			case '1':
				$DelType=SafeRequest("deltypes","post");
				if($DelType==2){
					for($i=0;$i<count($Arr);$i++){
						$sql="update s_article set S_IsHide=0 where S_ID=".$Arr[$i]."";
						$db->query($sql);
						}
					die("<script>jAlert('数据还原成功了！','操作提示',function(R){window.location='admin_article.php';})</script>");
					}
				elseif($DelType==3){
					for($i=0;$i<count($Arr);$i++){
						$sql="update s_article set S_IsHide=1 where S_ID=".$Arr[$i]."";
						$db->query($sql);
						}
					die("<script>jAlert('数据已放入回收站！','操作提示',function(R){window.location='admin_article.php';})</script>");						 					}
				else{
					for($i=0;$i<count($Arr);$i++){
						$sql="delete from s_article where S_ID=".$Arr[$i]."";
						$db->query($sql);
						}
					die("<script>jAlert('数据删除成功!','操作提示',function(R){window.location='admin_article.php';})</script>");						 					}	
				break;
			case '4':
				$ClassIDs=SafeRequest("ClassIDs","post");
					for($i=0;$i<count($Arr);$i++){
						$sql="update s_article set S_ClassID=".$ClassIDs." where S_ID=".$Arr[$i]."";
						$db->query($sql);
						}
				die("<script>jAlert('数据转移分类成功!！','操作提示',function(R){window.location='admin_article.php';})</script>");
				break;
			case '5':
				$TopicID=SafeRequest("TopicID","post");
					for($i=0;$i<count($Arr);$i++){
						$sql="update s_article set S_Topic=".$TopicID." where S_ID=".$Arr[$i]."";
						$db->query($sql);
						}
				die("<script>jAlert('数据转移专题成功!！','操作提示',function(R){window.location='admin_article.php';})</script>");
				break;
			case '6':
				$S_ID=RequestBox("S_ID");
				for($i=0;$i<count($Arr);$i++){
					$Url="mark/admin_spanarticleshow.php?sel=single";					
					echo "<script>spango(".$Arr[$i].",\"".$Url."&cid=0\");</script>";
					}
				die("<script>jAlert('数据批量生成成功!！','操作提示',function(R){window.location='?admin_article.php';})</script>");	
				break;	
			}
				
			

		}
?>
<?php include "admin_bottom.php"; ?>
</body>
</html>