<?php 
require "../Run.php";
require "../include/page.inc.php";
function sum_download($wapid,$gro){
	$sql = "SELECT count(*) FROM download WHERE siteid='{$wapid}' AND gro='{$gro}'";   
	$result = mysql_query($sql); 
	list($nums) = mysql_fetch_row($result);
	return $nums;
}

function get_page($wapid,$gro){
$page=$_GET['page'];
	if($page>=0){
	$page = 1;
	}elseif($page>sum_download($wapid,$gro)){
	$page = sum_download($wapid,$gro);
	}
	return $page;
}

function start($wapid,$gro,$listnums){
	$start=(get_page($wapid,$gro) - 1)*$listnums;
    return $start;
}
function get_list($wapid,$gro,$listnums){
	$start=start($wapid,$gro,$listnums);
	$sql="SELECT fileid,siteid,gro,title,file_path,file_ver,file_time,file_end,file_content,file_v,file_down,file_pic,file_auter,file_lan,file_pt FROM download WHERE siteid='{$wapid}' AND gro='{$gro}' ORDER BY fileid DESC LIMIT {$start},{$listnums}";
		$result = mysql_query($sql);      
			if($result && mysql_num_rows($result) > 0){
			$i = 0;
			while(list($fileid,$siteid,$gro,$title,$file_path,$file_ver,$file_time,$file_end,$file_content,$file_v,$file_down,$file_pic,$file_auter,$file_lan,$file_pt) = mysql_fetch_row($result)){
			 $div = $num++%2 == 0?'line1':'line2';
			$list.='<div class="'.$div.'"><a href="content.php?cid='.$gro.'&id='.$fileid.'&">'.$title.'</a></div>';
			$i++; 
		}
	}else{
		$list='<div cid="tip">暂时还木有任何记录</div>';
	}
	return $list;
}
//输出组合HTML
    
	$class_name = class_name($_GET['cid'],'cn',$wapid);
	$cid = $_GET['cid'];
	$gro = class_name($_GET['cid'],'gro',$wapid);
	$listnums = class_get_info($_GET['cid'],"listnums",$wapid);
if($listnums<=0||$listnums==NULL){
  $listnums=10;
  }
	echo head($class_name);
	echo UBB(class_get_info($_GET['cid'],"top_two",WAPID));
	echo topNav($class_name,'<a href="../index.php?cid='.$gro.'&">返回</a>','<a href="add.php?cid='.$_GET['cid'].'&">上传</a>');
	echo '<table class="bbs_sub"><tr><td class="left" '.$newcss.'><a href="list.php?action=new&cid='.$_GET['cid'].'&">最新</a></td><td class="center" '.$dtcss.'><a href="list.php?action=dt&cid='.$_GET['cid'].'&">动态</a></td><td class="right" '.$goodcss.'><a href="list.php?action=good&cid='.$_GET['cid'].'&">精华</a></td></tr></table>';
	echo get_list($wapid,$_GET['cid'],$listnums);
	$url = 'list.php?cid='.$_GET[cid].'&';
	echo '<div class="showpage">'.page(sum_download(WAPID,$_GET['cid']),$listnums,$url,NULL,'view').'</div>';
	echo UBB(class_get_info($_GET['cid'],"bottom_two",WAPID));
	echo footer(1);
?>