<?PHP
$list = $_REQUEST['list'];
$page = $_REQUEST['page'];
if(!is_numeric($page)) $page = 0;
else $page = max(0, min(5, $page));
switch($list)
{
case 'fist':
$id = 0;
$name = 'Fist Fighting';
break;
case 'club':
$id = 1;
$name = 'Club Fighting';
break;
case 'sword':
$id = 2;
$name = 'Sword Fighting';
break;
case 'axe':
$id = 3;
$name = 'Axe Fighting';
break;
case 'distance':
$id = 4;
$name = 'Distance Fighting';
break;
case 'shield':
$id = 5;
$name = 'Shielding';
break;
case 'fishing':
$id = 6;
$name = 'Fishing';
break;
case 'magic':
$name = 'Magic Level';
break;
default:
$name = 'Level';
$list = 'experience';
break;
}
$f = 'highscores-'.$list.'-'.$page.'.tmp';
if(file_exists($f) && filemtime($f) > (time() - 180))
$main_content .= file_get_contents($f);
else {
$offset = $page * 50;
if(isset($id))
$skills = $SQL->query('SELECT name,online,value,level,vocation,promotion FROM players,player_skills WHERE players.group_id < 4 AND players.id = player_skills.player_id AND player_skills.skillid = '.$id.' ORDER BY value DESC, count DESC LIMIT 50 OFFSET '.$offset);
elseif($list == "magic")
$skills = $SQL->query('SELECT name,online,maglevel,level,vocation,promotion FROM players WHERE players.group_id < 4 ORDER BY maglevel DESC, manaspent DESC LIMIT 50 OFFSET '.$offset);
elseif($list == "experience")
$skills = $SQL->query('SELECT name,online,level,experience,vocation,promotion FROM players WHERE players.group_id < 4 ORDER BY level DESC, experience DESC LIMIT 50 OFFSET '.$offset);
$main_content .= '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td> </td><td><center><h2>Ranking for '.$name.' on '.$config['server']['serverName'].'</h2></center><br/>';
$main_content .= '<table border="0" cellpadding="4" cellspacing="1" width="100%"><tr><td width="100%" align="right" valign="top">';
if($page > 0)
$links .= '<a href="?subtopic=highscores&list='.$list.'">Top</a> | <a href="?subtopic=highscores&list='.$list.($page != 1 ? '&page='.($page-1) : '').'">Rank '.(($page-1)*50+1).'-'.(($page)*50).'</a>';
if($page < 5)
$links .= ($page==0 ? '' : ' | ').'<a href="?subtopic=highscores&list='.$list.'&page='.($page+1).'">Rank '.(($page+1)*50+1).'-'.(($page+2)*50).'</a></td>';
$main_content .= $links.'</tr></table>';
$main_content .= '<table border="0" cellpadding="4" cellspacing="1" width="100%"><tr bgcolor="'.$config['site']['vdarkborder'].'"><td width="3%" class="white"><b>Rank</b></td><td width="75%" class="white"><b>Name</b></td><td width="15%" class="white"><b>Level</b></td>';
if($list == 'experience')
$main_content .= '<td class="white"><b>Points</b></td>';
$main_content .= '</tr>';
foreach($skills as $skill) {
if($list == 'magic')
$skill['value'] = $skill['maglevel'];
elseif($list == 'experience')
$skill['value'] = $skill['level'];
$i++;
$main_content .= '<tr bgcolor="'.$config['site'][(is_int($i / 2)) ? 'lightborder' : 'darkborder'].'"><td>'.($offset + $i).'</td><td><a href="?subtopic=characters&name='.urlencode($skill['name']).'">'.($skill['online']>0 ? '<font color="green">'.$skill['name'].'</font>' : '<font color="red">'.$skill['name'].'</font>').'</a><br/><small>'.$skill['level'].' '.$vocation_name[0][$skill['promotion']][$skill['vocation']].'</small></td><td>'.$skill['value'].'</td>';
if($list == 'experience')
$main_content .= '<td>'.$skill['experience'].'</td>';
$main_content .= '</tr>';
}
$main_content .= '</table><table border="0" cellpadding="4" cellspacing="1" width="100%"><tr><td align="right" valign="top">'.$links.'</tr></table></td><td width="3%"> </td><td width="100" valign="top" align="right"><table style="border:1px solid grey;width:135px" bgcolor="'.$config['site']['lightborder'].'" cellpadding="4" cellspacing="1"><tr bgcolor="'.$config['site']['darkborder'].'"><td><span style="font-size:10px;color:#625536">» Highscore Type</span></td></tr><tr bgcolor="'.$config['site']['lightborder'].'"><td>';
$i=0;
foreach(array('experience'=>'Level','magic'=>'Magic Level','fist'=>'Fist','club'=>'Club','sword'=>'Sword','axe'=>'Axe','distance'=>'Distance','shield'=>'Shielding','fishing'=>'Fishing') as $k => $v) {
$i++;
$main_content .= '<span style="font-size:10px;color:#625536">'.$i.'.</span> <a href="?subtopic=highscores&list='.$k.'"><span style="text-decoration:underline;font-weight:100;color:#493421;font-size:10px">'.$v.'</span></a><br/>';
}
$main_content .= '</td></tr></table></td><td> </td></tr></table>';
file_put_contents($f, $main_content);
}
?>