<?php 
    
    require "../../Run.php";
	require "../../include/getmkurl.fun.php";
 
    echo head('HTML自写模块');
	if($admin !=1 && $admin !=2){ 
	die ('权限不足');
	}
	
	if($_GET['action'] == 'del'){
	 if($_GET['type']== 'del'){
	 $result = mysql_query("DELETE FROM html WHERE htmlid='{$_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 html SET top='YES' WHERE htmlid='{$_GET["id"]}'";
	$result=mysql_query($sql);
	echo '<div class="tip">';
	if($result && mysql_affected_rows()>0){
	echo "推荐成功";
	}else{
	echo "推荐失败";
         }
	  }else{
	$sql="UPDATE html SET top='NULL' WHERE htmlid='{$_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||$_GET['cid']==''){
    /*栏目分类列表*/
     $sql="SELECT cid,cn,xuhao FROM class WHERE url='".get_mkid('html/list.php')."' AND siteid ='{$wapid}' ORDER BY cid DESC";
    $result = mysql_query($sql);
	echo '<div class="subtitle">HMTL自写栏目</div>';
	echo '<div class="content">';
    while(list($cid,$cn,$number) = mysql_fetch_row($result)){
	echo "[".$cid."]";
	echo "<a href=\"list.php?cid=".$cid."&page=1&id=".$articleid."\">".$cn."</a>"; 
	  }
	echo '</div>';
	echo "<div class=\"mylink\"><a href=\"../../admin/wap_admin.php?\">返回上级</a><a href=\"../../index.php?\">网站首页</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."\">添加HTML</a>.<a href=\"list.php?cid=0&sid=".$sid_info."\">所有记录</a></div>";
	            /*处理结果集*/
	      

	 if($where == 0){
     $sql = "SELECT htmlid,gro,userid,title,content FROM html ORDER BY htmlid DESC LIMIT $s,$limit";
	 /*执行数据查询语句*/  
     $result = mysql_query($sql);
	 }else{
	 $sql = "SELECT htmlid,gro,userid,title,content FROM html WHERE gro='{$where}' ORDER BY htmlid DESC LIMIT $s,$limit";
	 /*执行数据查询语句*/  
     $result = mysql_query($sql);
	 }
	 if($result && mysql_num_rows($result) > 0){
	 $i=0;
	
	 while(list($articleid,$cid,$userid,$title,$content) = 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 html ";
	 $result = mysql_query($sql);
	 }else{
	 $sql = "SELECT count(*) FROM html WHERE cid='{$where}'";
     $result = mysql_query($sql);
     };
	 list($num) = mysql_fetch_row($result);
     if($num < $limit){
     $pageNum = 1;       /*如果记录数小于限制数则总页数为1*/
	 }elseif($num > 10){
     $pageNum=$num / $limit;
     for($i = 0;$i < $pageNum;$i++){
     $pages=$i + 1;
     if($pages>$pageNum){
	 $pageNum = $pages;
	      }
	    }
	  }elseif($num == $limit){
	$pageNum = 1;/*如果相等则总页数为一*/
	}
	if($page > 1){
	$upage = $page - 1;
	$uppage = "<a href=\"index.php?cid=".$_GET['cid']."&page=".$upage."&sid=".$sid_info."\">上一页</a>";
	}else{
	$uppage = "上一页";
	}
				  /*判断是否显示下一页*/
	if($page < $pageNum){
	$dpage = $page + 1;
	$downpage="<a href=\"index.php?cid=".$_GET['cid']."&page=".$dpage."&sid=".$sid_info."\">下一页</a>";
	}else{
		   $downpage = "下一页";
		} 
  		echo "<div class=\"showpage\">".$uppage;
		echo "第".$page;
		echo "/";
		echo $pageNum;
        echo "页".$downpage."[共".$num."条记录]</div>";
		echo "<div class=\"mylink\"><a href=\"list.php?sid=".$sid_info."\">返回上级</a><a href=\"../../index.php?sid=".$sid_info."\">网站首页</a></div>";	
		}
	}
echo footer(1);	
   ?>