
<?php 
    
    require "../../Run.php";
    require "../../include/getmkurl.fun.php";
 
    echo head('友情链接管理'); 
	if($admin !=1 && $admin !=2){ 
	die ('权限不足');
	}
	
	if($_GET['action'] == 'del'){
	 if($_GET['type']== 'del'){
	 $result = mysql_query("DELETE FROM sitelink WHERE sitelinkid='{$_GET["id"]}' AND siteid='".WAPID."'");
	 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 sitelink SET list='1' WHERE sitelinkid='{$_GET["id"]}'";
	$result=mysql_query($sql);
	echo '<div class="tip">';
	if($result && mysql_affected_rows()>0){
	echo "审核成功";
	}else{
	echo "审核失败";
         }
	  }else{
	$sql="UPDATE sitelink SET list='0' WHERE sitelinkid='{$_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='.$sitelinkid.'&"</script></div>';
	
	}else{
	if($_GET['cid'] == NULL){
    /*栏目分类列表*/
    $sql="SELECT cid,cn,xuhao FROM class WHERE url='".get_mkid('sitelink/list.php')."' AND siteid='".WAPID."' ORDER BY cid DESC";
    $result = mysql_query($sql);
	echo '<div class="title">请选择栏目|<a href="?cid=0&">所有记录>></a></div>';
	$num=1;
    while(list($cid,$cn,$number) = mysql_fetch_row($result)){
	$div=$num++%2==0?'line1':'line2';
	echo '<div class="'.$div.'">';
	echo "[".$cid."]";
	echo "<a href=\"list.php?cid=".$cid."&page=1&id=".$sitelinkid."\">".$cn."</a>"; 
	echo "<a href=\"index.php?action=sitelink&type=Modclass&cid=".$cid."&page=".$_GET['page']."&sid=".$sid_info."\">
	[修改</a>"; 
	echo "<a href=\"index.php?action=sitelink&type=delclass&cid=".$cid."&page=".$_GET['page']."&sid=".$sid_info."\">
	删除]</a><br></div>"; 
	  }
	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=".$sitelinkid."\">前台友链上传</a>.<a href=\"mod_ad.php?cid=".$_GET['cid']."\">栏目广告</a>]</div>";
	            /*处理结果集*/
	      

	 if($where == 0){
     $sql="SELECT sitelinkid,gro,title,v,content,time,list FROM sitelink ORDER BY sitelinkid DESC LIMIT $s,$limit";
	 /*执行数据查询语句*/  
     $result = mysql_query($sql);
	 }else{
	 $sql = "SELECT sitelinkid,gro,title,v,content,time,list FROM sitelink WHERE gro='{$where}' AND siteid='".WAPID."' ORDER BY sitelinkid DESC LIMIT $s,$limit";
	 /*执行数据查询语句*/  
     $result = mysql_query($sql);
	 }
	 if($result && mysql_num_rows($result) > 0){
	 $i=0;
	 
	 while(list($sitelinkid,$gro,$title,$v,$content,$time,$list) = 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=".$sitelinkid."\">".$title."</a>";
	 if($list == '1'){
	 $iftop = 'qtop';
     $cn = '取消审核';
	 }else{
	 $iftop = 'get';
	 $cn = '审核';
	 }
	 echo "
	 <a href=\"mod.php?cid=".$_GET['cid']."&page=".$_GET['page']."&id=".$sitelinkid."&\">修</a>.
	 <a href=\"list.php?action=del&cid=".$_GET['cid']."&page=".$_GET['page']."&id=".$sitelinkid."\">删</a>.
	 <a href=\"list.php?action=top&type=".$iftop."&cid=".$_GET['cid']."&page=".$_GET['page']."&id=".$sitelinkid."\">".$cn."</a>";
	 echo '<br>';
	 echo '链接ID:'.$sitelinkid.' | 栏目ID:'.$gro.'<br>';
	 echo '</div>';
	 }
	
	 }else{
	 /*没有获取记录则输出*/
	 echo "你好，此栏目暂无记录或者此栏目不存在<br>";
	 }
	 if($where == 0){
	 $sql="SELECT count(*) FROM sitelink WHERE siteid={$wapid} ";
	 }else{
	 $sql = "SELECT count(*) FROM sitelink WHERE gro='{$where}' AND siteid={$wapid}";
     }
	 $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."\">上一页</a>";
	}else{
	$uppage = "上一页";
	}
				  /*判断是否显示下一页*/
	if($page < $pageNum){
	$dpage = $page + 1;
	$downpage="<a href=\"index.php?cid=".$_GET['cid']."&page=".$dpage."\">下一页</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\">返回上级</a><a href=\"../../index.php?\">网站首页</a></div>";	
		}
	}	
   ?>
     
</body></html>