
<?php 
    require "../../Run.php";
    require "../../include/page.inc.php";
    require "../../include/getmkurl.fun.php";
    echo head('文章管理').'<body>';
	if($admin !=1 && $admin !=2){ 
		die ('权限不足');
		}
	
	if($_GET['action'] == 'del'){
		if($_GET['type']== 'del'){
			$result = mysql_query("DELETE FROM article WHERE articleid='{$_GET["id"]}'");
			echo '<div class="subtitle">文章删除</div>';
			echo '<div class="tip">';
		if($result && mysql_affected_rows()>0){
			echo '成功删除';
				}else{
			echo "删除失败";
		}
	 echo '</div>';
	 echo '<div class="mylink"><a href="list.php?cid='.$_GET['cid'].'">返回文章列表</a></div>';
	 }else{
	echo '<div class="tip">确定删除此条记录吗？<br><a href="list.php?action=del&type=del&cid='.$_GET['cid'].'&id='.$_GET['id'].'">[确定，马上删除。]</a></div>';
	   }
	}elseif($_GET['action']=='top'){
	if($_GET['type'] == 'get'){
	$sql="UPDATE article SET top='YES' WHERE articleid='{$_GET["id"]}'";
	$result=mysql_query($sql);
	echo '<div class="tip">';
	if($result && mysql_affected_rows()>0){
	echo "推荐成功";
	}else{
	echo "推荐失败";
         }
	  }else{
	$sql="UPDATE article SET top='NULL' WHERE articleid='{$_GET["id"]}'";
	$result=mysql_query($sql);
	echo '<div class="tip">';
	if($result && mysql_affected_rows()>0){
	echo "取消推荐成功";
	}else{
	echo "取消推荐失败";
      }
	}
	echo '<script>window.location="list.php?cid='.$_GET['cid'].'&page='.$_GET['page'].'&id='.$articleid.'&"</script></div>';
	
	}else{
	if($_GET['cid'] == NULL){
    /*栏目分类列表*/
	echo '<div class="title">选择栏目|<a href="?cid=0">所有记录>></a></div>';
    $sql="SELECT cid,cn,xuhao FROM class WHERE url='".get_mkid('article/list.php')."' AND siteid ='{$wapid}' ORDER BY cid DESC";
    $result = mysql_query($sql);
	$dnum=0;
    while(list($cid,$cn,$number) = mysql_fetch_row($result)){
	$div=$dnum++%2==0?'line1':'line2';
	echo '<div class="'.$div.'">';
	echo "<a href=\"list.php?cid=".$cid."&page=1&id=".$articleid."&sid=".$sid_info."\">".'[ID'.$cid.']'.$cn."</a> </div>";
	/*echo "<a href=\".php?action=article&type=Modclass&cid=".$cid."&page=".$_GET['page']."\">
	修改</a>"; 
	echo "<a href=\"wap_admin.php?action=article&type=delclass&cid=".$cid."&page=".$_GET['page']."\">
	删除</a>
	";*/
	  }
	echo "<div class=\"mylink\"><a href=\"../../admin/wap_admin.php?sid=".$sid_info."\">返回上级</a><a href=\"../../index.php?sid=".$sid_info."\">网站首页</a></div>";
	}else{        
	$where = $_GET['cid']; 
	$limit = 20;
	$page=$_GET['page'];
	if($page <= 1){
	$page = 1;
	}else{ 
	$p = $page - 1;
	   }
	$s = $p*$limit;
			 /*top*/
    echo "<div class=\"subtitle\"><a href=\"add.php?cid=".$_GET['cid']."&id=".$articleid."&sid=".$sid_info."\">文章上传</a>.<a href=\"mod_ad.php?cid=".$_GET['cid']."&sid=".$sid_info."\">栏目属性</a><br>[ID:".$_GET['cid']."]</div>";
	            /*处理结果集*/
	      

	 if($where == 0){
     $sql = "SELECT articleid,gro,userid,title,content,top FROM article ORDER BY articleid DESC LIMIT $s,$limit";
	 /*执行数据查询语句*/  
     $result = mysql_query($sql);
	 }else{
	 $sql = "SELECT articleid,gro,userid,title,content,top FROM article WHERE gro='{$where}' ORDER BY articleid DESC LIMIT $s,$limit";
	 /*执行数据查询语句*/  
     $result = mysql_query($sql);
	 }
	 if($result && mysql_num_rows($result) > 0){ 
	 $i=0;
	 
	 while(list($articleid,$cid,$userid,$title,$content,$top) = mysql_fetch_row($result)){
	 $div=$num++%2==0?'line1':'line2';
	 echo '<div class="'.$div.'">';
	 echo "<a href=\"../content.php?cid=".$_GET['cid']."&page=".$_GET['page']."&id=".$articleid."&sid=".$sid_info."\">".$title."</a>";
	 if($top == 'YES'){
	 $iftop = 'qtop'; 
     $cn = '取消推荐';
	 }else{
	 $iftop = 'get';
	 $cn = '推荐';
	 }
	 echo "
	 <a href=\"mod.php?cid=".$_GET['cid']."&page=".$_GET['page']."&id=".$articleid."&sid=".$sid_info."\">修</a>.
	 <a href=\"list.php?action=del&cid=".$_GET['cid']."&page=".$_GET['page']."&id=".$articleid."&sid=".$sid_info."\">删</a>.
	 <a href=\"list.php?action=top&type=".$iftop."&cid=".$_GET['cid']."&page=".$_GET['page']."&id=".$articleid."&sid=".$sid_info."\">".$cn."</a>";
	 echo '<br>作者ID:'; 
	 echo $userid;
	 echo '文章ID:'.$articleid.' | 栏目ID:'.$cid.'<br>';
	 echo '</div>';
	 }
	
	 }else{
	 /*没有获取记录则输出*/
	 echo "你好，此栏目暂无记录或者此栏目不存在<br>";
	 }
	 if($where == 0){
	 $sql="SELECT count(*) FROM article WHERE siteid={$wapid}";
	 }else{
	 $sql = "SELECT count(*) FROM article WHERE gro='{$where}' AND siteid={$wapid}";
     }
	 $result = mysql_query($sql);
	 list($num) = mysql_fetch_row($result);
	 $url='list.php?cid='.$_GET['cid'].'&';
     echo '<div class="showpage">'.page($num,$limit,$url,$pagetype,'YES').'</div>';
     echo "<div class=\"mylink\"><a href=\"list.php?sid=".$sid_info."\">返回上级</a><a href=\"../../index.php?sid=".$sid_info."\">网站首页</a></div>";	
		}
	}	
   ?>
     
</body></html>