Commit c70155ce authored by Nemo Ma's avatar Nemo Ma Committed by GitHub

Merge pull request #209 from winddramon/nachster

winnerlist modernized
parents 504faea7 7878cf74
......@@ -2,8 +2,29 @@
<form method="post" name="info" onsubmit="winner.php">
<input type="hidden" id="command" name="command" value="info">
<input type="hidden" id="start" name="start" value="$gamenum">
<input type="hidden" id="gnum" name="gnum" value="">
<center>
<p>
<input type="checkbox" id="winner_show_wmode_2" name="winner_show_wmode_2" <!--{if !empty($winner_show_wmode_2)}-->checked<!--{/if}-->><a onclick="$('winner_show_wmode_2').click();">$gwin[2]</a>&nbsp;&nbsp;
<input type="checkbox" id="winner_show_wmode_3" name="winner_show_wmode_3" <!--{if !empty($winner_show_wmode_3)}-->checked<!--{/if}-->><a onclick="$('winner_show_wmode_3').click();">$gwin[3]</a>&nbsp;&nbsp;
<input type="checkbox" id="winner_show_wmode_5" name="winner_show_wmode_5" <!--{if !empty($winner_show_wmode_5)}-->checked<!--{/if}-->><a onclick="$('winner_show_wmode_5').click();">$gwin[5]</a>&nbsp;&nbsp;
<input type="checkbox" id="winner_show_wmode_7" name="winner_show_wmode_7" <!--{if !empty($winner_show_wmode_7)}-->checked<!--{/if}-->><a onclick="$('winner_show_wmode_7').click();">$gwin[7]</a>&nbsp;&nbsp;
搜索玩家:<input id="winner_show_winner" name="winner_show_winner" style="width: 120px;" type="text" value="$winner_show_winner">
<input type="button" class="cmdbutton" value="搜索" onclick="document.info.command.value='list';document.info.submit();">
</p>
<p>
<!--{if $result_num > $winlimit}-->
<!--{if $start != $largest_mark}--><a onclick="document.info.start.value = '$largest_mark';document.info.command.value='list';document.info.submit();">第{$largest_mark}回</a>&nbsp;&nbsp;...&nbsp;&nbsp;<!--{/if}-->
<!--{if $larger_mark && $larger_mark < $largest_mark}--><a onclick="document.info.start.value = '$larger_mark';document.info.command.value='list';document.info.submit();">第{$larger_mark}回</a>&nbsp;&nbsp;<!--{/if}-->
<span class="evergreen b">第{$start}回</span>&nbsp;&nbsp;
<!--{if $smaller_mark && $smaller_mark > $smallest_mark}--><a onclick="document.info.start.value = '$smaller_mark';document.info.command.value='list';document.info.submit();">第{$smaller_mark}回</a>&nbsp;&nbsp;<!--{/if}-->
<!--{if $start != $smallest_mark}-->...&nbsp;&nbsp;<a onclick="document.info.start.value = '$smallest_mark';document.info.command.value='list';document.info.submit();">第{$smallest_mark}回</a><!--{/if}-->
&nbsp;&nbsp;&nbsp;<input id="winnermark" style="width: 60px;" type="text" value="$start">
&nbsp;<input style="width: 80px" type="button" value="跳转" onclick="document.info.start.value = $('winnermark').value;document.info.command.value='list';document.info.submit();">
<!--{/if}-->
</p>
<br>
<TABLE border="1" cellspacing="0" cellpadding="0">
<TR height="20">
<TD class="b1" width="30px"><span></span></TD>
......@@ -55,19 +76,11 @@
<input type="button" value="角色信息" <!--{if $info['wmode'] && $info['wmode'] != 1 && $info['wmode'] !=4 && $info['wmode'] != 6}-->onclick="$('command').value='info';$('gnum').value='$gid';document.info.submit();"<!--{else}-->disabled<!--{/if}-->>
<!--{if $info['wmode'] && $info['wmode'] !=4}--><span class="white"><a href="winner.php?command=news&gnum=$info[gid]">📼</a></span><!--{else}--> <!--{/if}-->
<input type="button" value="该局状况" <!--{if $info['wmode'] && $info['wmode'] !=4}-->onclick="$('command').value='news';$('gnum').value='$gid';document.info.submit();"<!--{else}-->disabled<!--{/if}-->>
$download_buttons[$gid]
<!--{if !empty($download_buttons[$gid])}-->$download_buttons[$gid]<!--{/if}-->
</span>
</TD>
</TR>
<!--{/loop}-->
</TABLE>
</center>
</form>
<form method="post" name="list" action="winner.php">
<input type="hidden" name="command" value="list">
<input type="hidden" name="start" value="$gamenum">
<input style="width: 120px;" type="button" value="最近 {$winlimit} 回" onClick="document['list'].submit();">
<br>
<!--{if isset($listinfo)}-->$listinfo<!--{/if}-->
</form>
</form>
\ No newline at end of file
......@@ -4,7 +4,6 @@ define('CURSCRIPT', 'winner');
require './include/common.inc.php';
if(!isset($command)){$command = 'ref';}
if($command == 'info') {
$result = $db->query("SELECT * FROM {$gtablepre}winners WHERE gid='$gnum' LIMIT 1");
......@@ -23,50 +22,148 @@ if($command == 'info') {
$hnewsinfo = readover($hnewsfile);
}
} else {
$download_button = [];
$max_gamenum = 0;
$result = $db->query("SELECT gid FROM {$gtablepre}winners ORDER BY gid DESC LIMIT 1");
if ($db->num_rows($result)) {
$tmp_rst=$db->fetch_array($result);
$max_gamenum = $tmp_rst['gid'];
}
//$start预处理
if(!isset($start) || !$start){
$result = $db->query("SELECT gid,name,nick,icon,gd,wep,wmode,teamID,teamMate,teamIcon,getime,motto,hdp,hdmg,hkp,hkill FROM {$gtablepre}winners ORDER BY gid desc LIMIT $winlimit");
} else {
$result = $db->query("SELECT gid,name,nick,icon,gd,wep,wmode,teamID,teamMate,teamIcon,getime,motto,hdp,hdmg,hkp,hkill FROM {$gtablepre}winners WHERE gid<='$start' ORDER BY gid desc LIMIT $winlimit");
$start = 0;
}else{
$start = (int)$start;
if($start > $max_gamenum) $start = $max_gamenum;
elseif($start < $winlimit) $start = $winlimit;
}
//生成query
//gid起始条件(翻页)
$query_gid = $start > 0 ? "gid<='$start'" : "";
//gmode条件(游戏模式)
$query_gtype = '';
// $show_gtype_arr = array();
// for($i=0;$i<=20;$i++) {
// if(!empty(${'winner_show_gtype_'.$i})) $show_gtype_arr[] = $i;
// }
// sort($show_gtype_arr);
// if(!empty($show_gtype_arr)) {
// $query_gtype = "gametype IN ('".implode("','",$show_gtype_arr)."')";
// }
//wmode条件(胜利类型)
$query_wmode = ''; $show_wmode_arr = array();
for($i=1;$i<=7;$i++) {
if(!empty(${'winner_show_wmode_'.$i})) $show_wmode_arr[] = $i;
}
sort($show_wmode_arr);
if(!empty($show_wmode_arr)) {
$query_wmode = "wmode IN ('".implode("','",$show_wmode_arr)."')";
}
while($wdata = $db->fetch_array($result)) {
$wdata['date'] = date("Y-m-d",$wdata['getime']);
$wdata['time'] = date("H:i:s",$wdata['getime']);
if(!empty($wdata['teamMate']))
{
$wdata['teamID'] = '<span class="gold">【团队 - '.$wdata['teamID'].'】</span>';
$wdata['iconImg'] = 't_'.$wdata['teamIcon'].'.gif';
$wdata['nickinfo'] = '<span class="gold">团队胜利</span>';
$wdata['name'] = explode("+",$wdata['teamMate']);
//winner条件(获胜者)
$query_winner = '';
if(!empty($winner_show_winner)) {
$query_winner = "name='$winner_show_winner'";
}
//先不拼接gid条件(当前局数指针),为了获得所有符合查找条件的结果gid,并获取最大和最小值
$query_where = '';
if(!empty($query_wmode) || !empty($query_gtype) || !empty($query_winner)) {
$query_where .= $query_wmode;
$query_where .= (!empty($query_where) && !empty($query_gtype) ? ' AND ' : '') . $query_gtype;
$query_where .= (!empty($query_where) && !empty($query_winner) ? ' AND ' : '') . $query_winner;
$query_where = 'WHERE '.$query_where;
}
$query_count = "SELECT gid FROM {$gtablepre}winners $query_where ORDER BY gid DESC";
$result = $db->query($query_count);
$result_num = $db->num_rows($result);
$max_result_gamenum = $min_result_gamenum = 0;
$winfo = array();
$largest_mark = $larger_mark = $smaller_mark = $smallest_mark= 0;
if($result_num){
$wgidarr = Array();
while($wgid = $db->fetch_array($result)) {
$wgidarr[] = $wgid['gid'];
}
rsort($wgidarr);
$max_result_gamenum = $wgidarr[0];
$min_result_gamenum = $wgidarr[$result_num-1];
//然后拼接含gid(当前局数指针)的WHERE条件
$query_where = '';
if(!empty($query_gid) || !empty($query_wmode) || !empty($query_gtype) || !empty($query_winner)) {
$query_where .= $query_gid;
$query_where .= (!empty($query_where) && !empty($query_wmode) ? ' AND ' : '') . $query_wmode;
$query_where .= (!empty($query_where) && !empty($query_gtype) ? ' AND ' : '') . $query_gtype;
$query_where .= (!empty($query_where) && !empty($query_winner) ? ' AND ' : '') . $query_winner;
$query_where = 'WHERE '.$query_where;
}
else
{
$wdata['iconImg'] = $wdata['gd'] == 'f' ? 'f_'.$wdata['icon'].'.gif' : 'm_'.$wdata['icon'].'.gif';
if(!empty($wdata['nick']) && !is_numeric($wdata['nick']))
$query_limit = "SELECT gid,name,nick,icon,gd,wep,wmode,teamID,teamMate,teamIcon,getime,motto,hdp,hdmg,hkp,hkill FROM {$gtablepre}winners $query_where ORDER BY gid DESC LIMIT $winlimit";
//echo $query;
$result = $db->query($query_limit);
$download_button = [];
while($wdata = $db->fetch_array($result)) {
$wdata['date'] = date("Y-m-d",$wdata['getime']);
$wdata['time'] = date("H:i:s",$wdata['getime']);
if(!empty($wdata['teamMate']))
{
$wdata['nickinfo'] = titles_get_desc($wdata['nick'],1);
$wdata['teamID'] = '<span class="gold">【团队 - '.$wdata['teamID'].'】</span>';
$wdata['iconImg'] = 't_'.$wdata['teamIcon'].'.gif';
$wdata['nickinfo'] = '<span class="gold">团队胜利</span>';
$wdata['name'] = explode("+",$wdata['teamMate']);
}
else
{
$wdata['nickinfo'] = (!empty($wdata['nick']) || $wdata['nick'] === '0') ? titles_get_desc($wdata['nick']) : '';
$wdata['iconImg'] = $wdata['gd'] == 'f' ? 'f_'.$wdata['icon'].'.gif' : 'm_'.$wdata['icon'].'.gif';
if(!empty($wdata['nick']) && !is_numeric($wdata['nick']))
{
$wdata['nickinfo'] = titles_get_desc($wdata['nick'],1);
}
else
{
$wdata['nickinfo'] = (!empty($wdata['nick']) || $wdata['nick'] === '0') ? titles_get_desc($wdata['nick']) : '';
}
}
$winfo[$wdata['gid']] = $wdata;
//遍历./records/$wdata['gid']/下的所有gz文件
$filelist = glob("./records/{$wdata['gid']}/**/*.gz");
foreach ($filelist as $file) {
//下载按钮,html
$dirname = basename(dirname($file));
if(empty($download_buttons[$wdata['gid']])) $download_buttons[$wdata['gid']] = "";
$download_buttons[$wdata['gid']] .= "<br><a href=\"$file\" download=\"$dirname\">下载 $dirname</a>";
}
}
//判断分页情况
$winfo_keys=array_keys($winfo);rsort($winfo_keys);
$max_wdata_num=$winfo_keys[0];
$min_wdata_num = $winfo_keys[sizeof($winfo_keys)-1];
if($result_num > $winlimit){
if(!isset($start) || !$start) $start = $max_result_gamenum;
$largest_mark = $max_result_gamenum;
$smallest_mark = max($min_result_gamenum, $winlimit);
if(in_array($start, $wgidarr)) {
$start_n = array_search($start, $wgidarr);
}else{
$tmp_wgidarr = $wgidarr;
$tmp_wgidarr[] = $start;
rsort($tmp_wgidarr);
$start_n = array_search($start, $tmp_wgidarr);
}
if($start < $largest_mark) {
//上一页,需要用到所有符合条件的gid数组$wgidarr
//注意这里larger和smaller是从gid绝对值角度而言的,从数组角度larger的下标反而小,smaller的下标反而大
$larger_n = max(0, $start_n - $winlimit);
$larger_mark = $wgidarr[$larger_n];
}
if($start > $smallest_mark) {
$smaller_n = min($result_num-1, $start_n + $winlimit);
$smaller_mark = $wgidarr[$smaller_n];
}
}
$winfo[$wdata['gid']] = $wdata;
//遍历./records/$wdata['gid']/下的所有gz文件
$filelist = glob("./records/{$wdata['gid']}/**/*.gz");
foreach ($filelist as $file) {
//下载按钮,html
$dirname = basename(dirname($file));
$download_buttons[$wdata['gid']] .= "<br><a href=\"$file\" download=\"$dirname\">下载 $dirname</a>";
}
}
$listnum = floor($gamenum/$winlimit);
for($i=0;$i<$listnum;$i++) {
$snum = ($listnum-$i)*$winlimit;
$enum = $snum-$winlimit+1;
$listinfo .= "<input style='width: 120px;' type='button' value='{$snum} ~ {$enum} 回' onClick=\"document['list']['start'].value = '$snum'; document['list'].submit();\">";
if(is_int(($i+1)/3)&&$i){$listinfo .= '<br>';}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment