<?php
if (!defined('access') || !access) {
	die();
}

if (!isset($srvInfo) || !is_array($srvInfo)) {
	$serverInfoCache = LoadCacheData('server_info.cache');
	$srvInfo = (is_array($serverInfoCache) && isset($serverInfoCache[1][0])) ? explode('|', $serverInfoCache[1][0]) : array();
}
$onlinePlayers = isset($srvInfo[3]) ? $srvInfo[3] : 0;

if (!isLoggedIn()) {
	echo '<div class="nex-widget nex-widget--login">';
	echo '<h3>' . htmlspecialchars(lang('module_titles_txt_2'), ENT_QUOTES, 'UTF-8') . '</h3>';
	echo '<form class="nex-form" action="' . __BASE_URL__ . 'login" method="post">';
	echo '<input type="text" name="webengineLogin_user" required placeholder="' . htmlspecialchars(lang('login_txt_1'), ENT_QUOTES, 'UTF-8') . '" autocomplete="username">';
	echo '<input type="password" name="webengineLogin_pwd" required placeholder="' . htmlspecialchars(lang('login_txt_2'), ENT_QUOTES, 'UTF-8') . '" autocomplete="current-password">';
	echo '<button type="submit" name="webengineLogin_submit" value="submit" class="nex-btn nex-btn--primary nex-btn--block">' . htmlspecialchars(lang('login_txt_3'), ENT_QUOTES, 'UTF-8') . '</button>';
	echo '<a class="nex-inline-link" href="' . __BASE_URL__ . 'forgotpassword">' . htmlspecialchars(lang('login_txt_4'), ENT_QUOTES, 'UTF-8') . '</a>';
	echo '</form></div>';
}

if (isLoggedIn()) {
	echo '<div class="nex-widget nex-widget--usercp">';
	echo '<h3>' . htmlspecialchars(lang('usercp_menu_title'), ENT_QUOTES, 'UTF-8') . '</h3>';
	templateBuildUsercp();
	echo '</div>';
}

echo '<div class="nex-widget">';
echo '<h3>' . htmlspecialchars(lang('sidebar_srvinfo_txt_1'), ENT_QUOTES, 'UTF-8') . '</h3>';
echo '<table class="nex-table">';
if (check_value(config('server_info_season', true))) {
	echo '<tr><td>' . htmlspecialchars(lang('sidebar_srvinfo_txt_6'), ENT_QUOTES, 'UTF-8') . '</td><td>' . htmlspecialchars(config('server_info_season', true), ENT_QUOTES, 'UTF-8') . '</td></tr>';
}
if (check_value(config('server_info_exp', true))) {
	echo '<tr><td>' . htmlspecialchars(lang('sidebar_srvinfo_txt_7'), ENT_QUOTES, 'UTF-8') . '</td><td>' . htmlspecialchars(config('server_info_exp', true), ENT_QUOTES, 'UTF-8') . '</td></tr>';
}
if (check_value(config('server_info_masterexp', true))) {
	echo '<tr><td>' . htmlspecialchars(lang('sidebar_srvinfo_txt_8'), ENT_QUOTES, 'UTF-8') . '</td><td>' . htmlspecialchars(config('server_info_masterexp', true), ENT_QUOTES, 'UTF-8') . '</td></tr>';
}
if (check_value(config('server_info_drop', true))) {
	echo '<tr><td>' . htmlspecialchars(lang('sidebar_srvinfo_txt_9'), ENT_QUOTES, 'UTF-8') . '</td><td>' . htmlspecialchars(config('server_info_drop', true), ENT_QUOTES, 'UTF-8') . '</td></tr>';
}
echo '<tr><td>' . htmlspecialchars(lang('sidebar_srvinfo_txt_2'), ENT_QUOTES, 'UTF-8') . '</td><td><strong>' . number_format(isset($srvInfo[0]) ? (float) $srvInfo[0] : 0) . '</strong></td></tr>';
echo '<tr><td>' . htmlspecialchars(lang('sidebar_srvinfo_txt_3'), ENT_QUOTES, 'UTF-8') . '</td><td><strong>' . number_format(isset($srvInfo[1]) ? (float) $srvInfo[1] : 0) . '</strong></td></tr>';
echo '<tr><td>' . htmlspecialchars(lang('sidebar_srvinfo_txt_4'), ENT_QUOTES, 'UTF-8') . '</td><td><strong>' . number_format(isset($srvInfo[2]) ? (float) $srvInfo[2] : 0) . '</strong></td></tr>';
if (check_value(config('maximum_online', true))) {
	echo '<tr><td>' . htmlspecialchars(lang('sidebar_srvinfo_txt_5'), ENT_QUOTES, 'UTF-8') . '</td><td class="nex-online-cell">' . number_format($onlinePlayers) . '</td></tr>';
}
echo '</table></div>';

templateCastleSiegeWidget();
