<?php
/**
 * WebEngine CMS
 * https://webenginecms.org/
 * 
 * @version 1.0.9.7
 * @author Lautaro Angelico <http://lautaroangelico.com/>
 * @copyright (c) 2013-2017 Lautaro Angelico, All Rights Reserved
 * 
 * Licensed under the MIT license
 * http://opensource.org/licenses/MIT
 */

try {
	
	echo '<div class="page-title"><span>'.lang('module_titles_txt_10',true).'</span></div>';
	
	$Rankings = new Rankings();
	$Rankings->rankingsMenu();
	loadModuleConfigs('rankings');
	
	if(!mconfig('rankings_enable_votes')) throw new Exception(lang('error_44',true));
	if(!mconfig('active')) throw new Exception(lang('error_44',true));
	
	$ranking_data = LoadCacheData('rankings_votes.cache');
	if(!is_array($ranking_data)) throw new Exception(lang('error_58',true));
	
	$showPlayerCountry = mconfig('show_country_flags') ? true : false;
	$charactersCountry = loadCache('character_country.cache');
	if(!is_array($charactersCountry)) $showPlayerCountry = false;
	
	$onlineCharacters = array();
	if(mconfig('show_online_status')) {
		$onlineCharacters = loadCache('online_characters.cache');
	}
	
	// RANKINGS FILTER
	echo '<div class="text-center">';
		echo '<ul class="rankings-class-filter">';
			echo '<li><a onclick="rankingsFilterRemove()" class="rankings-class-filter-selection">'.getPlayerClassAvatar(-1, true, false, 'rankings-class-filter-image').'<br />All</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(0,1,3,7)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(0, true, false, 'rankings-class-filter-image').'<br />Wizards</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(16,17,19,23)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(16, true, false, 'rankings-class-filter-image').'<br />Knights</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(32,33,35,39)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(32, true, false, 'rankings-class-filter-image').'<br />Elves</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(48,50,54)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(48, true, false, 'rankings-class-filter-image').'<br />Gladiators</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(64,66,70)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(64, true, false, 'rankings-class-filter-image').'<br />Lords</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(80,81,83,87)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(80, true, false, 'rankings-class-filter-image').'<br />Summoners</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(96,98,102)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(96, true, false, 'rankings-class-filter-image').'<br />Fighters</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(112,114,118)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(112, true, false, 'rankings-class-filter-image').'<br />Lancers</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(128,129,131,135)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(128, true, false, 'rankings-class-filter-image').'<br />Rune Wizards</a></li>';
			echo '<li><a onclick="rankingsFilterByClass(144,145,147,151)" class="rankings-class-filter-selection rankings-class-filter-grayscale">'.getPlayerClassAvatar(144, true, false, 'rankings-class-filter-image').'<br />Slayers</a></li>';
		echo '</ul>';
	echo '</div>';
	// <-- RANKINGS FILTER END
	
	echo '<table class="rankings-table">';
	echo '<tr>';
	if(mconfig('rankings_show_place_number')) {
		echo '<td style="font-weight:bold;"></td>';
	}
	if($showPlayerCountry) echo '<td style="font-weight:bold;">'.lang('rankings_txt_33').'</td>';
	echo '<td style="font-weight:bold;">'.lang('rankings_txt_11',true).'</td>';
	echo '<td style="font-weight:bold;">'.lang('rankings_txt_10',true).'</td>';
	echo '<td style="font-weight:bold;">'.lang('rankings_txt_32',true).'</td>';
	if(mconfig('show_location')) echo '<td style="font-weight:bold;">'.lang('rankings_txt_34',true).'</td>';
	echo '</tr>';
	$i = 0;
	foreach($ranking_data as $rdata) {
		if($i>=1) {
			$characterIMG = getPlayerClassAvatar($rdata[2], true, true, 'rankings-class-image');
			$onlineStatus = mconfig('show_online_status') ? in_array($rdata[0], $onlineCharacters) ? '<img src="'.__PATH_ONLINE_STATUS__.'" class="online-status-indicator"/>' : '<img src="'.__PATH_OFFLINE_STATUS__.'" class="online-status-indicator"/>' : '';
			echo '<tr data-class-id="'.$rdata[2].'">';
			if(mconfig('rankings_show_place_number')) {
				echo '<td class="rankings-table-place">'.$i.'</td>';
			}
			if($showPlayerCountry) echo '<td><img src="'.getCountryFlag($charactersCountry[$rdata[0]]).'" /></td>';
			echo '<td>'.$characterIMG.'</td>';
			echo '<td>'.playerProfile($rdata[0]).$onlineStatus.'</td>';
			echo '<td>'.number_format($rdata[1]).'</td>';
			if(mconfig('show_location')) echo '<td>'.returnMapName($rdata[3]).'</td>';
			echo '</tr>';
		}
		$i++;
	}
	echo '</table>';
	if(mconfig('rankings_show_date')) {
		echo '<div class="rankings-update-time">';
		echo ''.lang('rankings_txt_20',true).' ' . date("m/d/Y - h:i A",$ranking_data[0][0]);
		echo '</div>';
	}
	
} catch(Exception $ex) {
	message('error', $ex->getMessage());
}