<?php
if(empty($op)) $op='my';
?>
  <!--- content -->
  <div class="neir">
    <div class="top">文章管理</div>
      <div class="content">
		<div class="main_nav">
			<ul>
				<li class="<?php if($op=='ds'){ echo 'nava_4';}else{ echo 'navb_5';}?>"><a href="?ac=news&op=ds">待审文章</a></li>
				<li class="<?php if($op=='my'){ echo 'nava_4';}else{ echo 'navb_5';}?>"><a href="?ac=news&op=my">我的文章</a></li>
			</ul>
			<div class="action"><a href="?ac=news&op=add">编写文章</a></div>
		</div>
		<div class="main_nav2">
<?php 
if($op=="add"){
      $name='';
      $cid='';
      $neir='';
      $classname='';
      $do='add';
   if(!empty($id)){
      global $db;
      $row=$db->getrow("select * from ".Getdbname('news')." where CS_ID=".$id."");
      if($row){
          $class=$db->getrow("select * from ".Getdbname('class')." where CS_ID=".$row['CS_CID']."");
          $name=$row['CS_Name'];
          $cid=$row['CS_CID'];
          $neir=$row['CS_Content'];
          $classname=$class['CS_Name'];
          $do='edit&id='.$id;
       }
   }
?>
<script type="text/javascript" charset="utf-8" src="../public/editor/kindeditor.js"></script>
<script type="text/javascript"> KE.show({
	id : 'CS_Content',
	resizeMode : 1,
	allowPreviewEmoticons : false,
	allowUpload : false,
	items : [
	'source', '|', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
	'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
	'insertunorderedlist', '|', 'image', 'link', 'unlink']
	});
</script>
<script language="javascript">
$(document).ready(function(){
	$("#addnews").click(function(){
		var CS_Name=$("#CS_Name").val();
		var CS_CID=$("#CS_CID").val();
		var CS_Content=$("#CS_Content").val();
	if(CS_Name==""){
		$("#CS_Name").css("border","1px solid red");
		$("#Msg").text("出错了，请填写文章标题！").css("color","red");
                alert("请填写文章标题！");
		return false;
		}
	else if(CS_CID=="0"){
		$("#Msg").text("出错了，请选择文章分类！").css("color","red");
                alert("请选择文章分类！");
		return false;
		}
	else if(CS_Content==""){
		$("#Msg").text("出错了，请填写文章内容！").css("color","red");
                alert("请填写文章内容！");
		return false;
		}
	});
});
</script>
	<form action="do.php?ac=news&op=<?php echo $do?>" id="form" name="form" method="post">
	<table class="user_mod_list" cellpadding="0" cellspacing="0">
		<tr><td height='50'><span class="t"><i>*</i>文章标题：</span><input type="text" class="user_reg_input" id="CS_Name" name="CS_Name" value="<?php echo $name?>"><span class="reg_msg" id="title_info">请输入文章的标题。</span></td></tr>
		<tr><td height='50'><span class="t"><i>*</i>文章分区：</span><span class="select"><select name="CS_CID" id="CS_CID">
<option value="0">--请选择--</option>
<?php 
      $sqlc="select * from ".Getdbname('class')." where CS_SID=2";
      $results=$db->query($sqlc);
	if($results){
	   while ($row1=$db->fetch_array($results)){
             if($row1['CS_ID']==$cid){
                    echo '<option value="'.$row1['CS_ID'].'" selected>'.$row1['CS_Name'].'</option>';
             }else{
                    echo '<option value="'.$row1['CS_ID'].'">'.$row1['CS_Name'].'</option>';
             }
           }
        }
?>
</select></span><span class="reg_msg" id="cid_info">请选择文章的分区。</span></td></tr>
		<tr><td style="clear:both; height:280px;"><span class="t"><i>*</i>文章内容：</span><textarea style="width:450px; height:280px;" id="CS_Content" name="CS_Content"><?php echo $neir?></textarea></td></tr>
	</table>
	<div style="padding-top:10px;margin-left:150px;"><span class="button-main"><span><button type="submit" id="addnews" >确定发布</button></span></span><div id="Msg"></div></div>
	</form>
<?php }else{ ?>
		<table class="song_list" cellpadding="0" cellspacing="0">
                <tr>
			<th>标题</th><th>浏览</th><th class="td_time">发布时间</th><th>修改</th><th>删除</th>
		</tr>
<?php
	$sql="select * from ".Getdbname('news')." where 1=1";
        $sql.=" and cs_user='".$cscms_name."'";
        if($op=='ds'){
              $sql.=' and cs_yid=1';
        }else{
              $sql.=' and cs_yid=0';
        }
        $sql.=' order by cs_addtime desc';
		$Arr=getuserpage($sql,"15");//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$numdate="a";
		if($result){
			while ($row = $db ->fetch_array($result)){
		        $numdate="b";

	 	echo "<tr>
			<td  width=\"350\"><div class=\"weibo_kuan\">
                   <a href=\"".LinkUrl('show','news','id',$row['CS_CID'],$row['CS_ID'])."\"  target=\"_blank\"> ".$row['CS_Name']."</a></div></td><td>".$row['CS_Hits']."</td><td>".datetime($row['CS_AddTime'])."</td><td><a href=\"?ac=news&op=add&id=".$row['CS_ID']."\" class=\"song_alter\" title=\"修改\">修改</a></td><td><a onclick=\"return confirm('确定要删除吗？删除之后将无法恢复！');\" class=\"song_del\" href=\"javascript:delnews('".$row['CS_ID']."')\">删除</a></td>
		</tr>";
	                }
                }
        if($numdate=="a") echo '<tr><td>没有相关记录!</td></tr>';
?>
		</table>
                </div>	
		<div class="page">
		<div class="pages">
                       <?php echo $Arr[0];?>
               </div>
<?php } ?>
	</div>
      </div>
    <div class="end"></div>
  </div>