<?php
!defined("MONKEYMAO") && die("Accessed Defined!");
	$sorts=$sortselect=array();
	$query = $db -> query("SELECT * FROM {$tablepre}picsort ORDER BY ordermode ");
	while($sort = $db -> fetch_array($query)){
		$sorts[$sort['id']]=$sort;
		$sortselect[$sort['upid']][$sort['id']]=$sort;
	}
	$id = ispage($id) ? $id : 0;
	$select = sortselect($sortselect,$id);
	
	$sql = 	$id ? "WHERE id='$id'" : '';
	

	if($keyword) {
		$keyword=addslashes($keyword);
		$urladd = '&keyword='.$keyword;
		$sql =  "WHERE pname LIKE '%$keyword%'" ;
	}
	$page = ispage($page) ? $page : 1;
	$pagenum = 20;
	$start_limit = ($page-1) * $pagenum;	
	$pics = array();
	$query = $db -> query("SELECT COUNT(*) FROM {$tablepre}pic $sql");
	$lines = $db -> result($query, 0);
	$paging = paging($lines, $pagenum, $page, 'index.php?action=pic&id='.$id.$urladd);
	$query = $db -> query("SELECT * FROM {$tablepre}pic $sql  ORDER BY postime DESC LIMIT $start_limit, $pagenum");
	while($pic = $db -> fetch_array($query)){
		$pic['folderdir']  = 	$sorts[$pic['id']]['folderdir'];
		$pic['sortname'] = 	$sorts[$pic['id']]['sortname'];
		$pic['postime'] = gmdate("$dateformat $timeformat", $pic['postime'] + ($timeoffset * 3600));
		$pics[$pic['pid']] = $pic;
	}
	include theme('pic', 'themes/admin', 'admin');

?>