<?php
	@ob_start();
	include 'include/functions/header.php';
?>

<style>
	.btn-custom-pin {
		background-image: url(../img/btn_left_sidebar.png);
		background-position: center;
		background-repeat: no-repeat;
		background-size: cover;
		width: 106px;
		height: 34px;
		font-family: 'OpenSans-ExtraBold', serif;
		font-size: 12px;
		text-transform: uppercase;
		color: #1c0e0e;
		align-items: center;
		text-align: center;
		position: relative;
		display: flex;
		margin: 0 auto;
		justify-content: center;
	}
</style>

<!DOCTYPE html>
<html lang="<?php print $language_code; ?>">
	<head>
		<title><?php print $site_title.' - '.$title; if($offline) print ' - '.$lang['server-offline']; ?></title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		
		<link rel="shortcut icon" href="<?php print $site_url; ?>images/favicon.ico?v=" />
		
        <link rel="stylesheet" href="<?php print $site_url; ?>css/font-awesome.min.css">
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
		<link href="<?php print $site_url; ?>css/style.css" rel="stylesheet" type="text/css">
		<link href="<?php print $site_url; ?>css/responsive.css" rel="stylesheet" type="text/css">
		<?php if($page=="admin" && $a_page=="player_edit") { ?>
		<link rel='stylesheet' href='<?php print $site_url; ?>css/bootstrap-select.css'/>
		<?php } ?>
		<style>
			.large:hover {
				height: <?php print 45*count($json_languages['languages']); ?>px;
			}
		</style>
		
		<script src="https://www.google.com/recaptcha/api.js" async defer></script>
	</head>
</html>
<body>
    <ul class="languagepicker roundborders large">
		<?php
		print '<a href="javascript:void(0)"><li><img width="24" src="'.$site_url.'images/flags/'.$language_code.'.png"/></li></a>';
			foreach($json_languages['languages'] as $key => $value)
				if($key!=$language_code)
					print '<a href="'.$site_url.'?lang='.$key.'"><li><img width="24" src="'.$site_url.'images/flags/'.$key.'.png"/></li></a>';
		?>
	</ul>
	<video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop">
		<source src="<?php print $site_url; ?>header-bg.mp4" type="video/mp4">
	</video>
    <nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="mainNav">
        <div class="container">
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
			<span class="navbar-toggler-icon"></span>
		</button>
            <div class="collapse navbar-collapse" id="navbarResponsive">
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item">
                        <a class="nav-link js-scroll-trigger" href="<?php print $site_url; ?>news"><?php print $lang['news']; ?></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link js-scroll-trigger" href="<?php print $site_url; ?>download"><?php print $lang['download']; ?></a>
                    </li>
					<?php if(!$database->is_loggedin()) { ?>
                    <li class="nav-item">
                        <a class="nav-link js-scroll-trigger" href="<?php print $site_url; ?>users/register"><?php print $lang['register']; ?></a>
                    </li>
					<?php } ?>
                    <li class="nav-item">
                        <a class="nav-link js-scroll-trigger" href="<?php print $site_url; ?>ranking/players"><?php print $lang['ranking']; ?></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link js-scroll-trigger" href="<?php print $social_links['discord']; ?>" target="_blank">Discord</a>
                    </li>
					<?php if($database->is_loggedin()) { ?>
                    <li>
                        <a href="<?php print $site_url; ?>user/administration" style="display: flex; justify-content: center;">
                            <div class="btn-custom btn-login">
                                <div class="btn-text-center"><?php print $lang['account-data']; ?></div>
                            </div>
                        </a>
                    </li>
					<?php } ?>
                </ul>
            </div>
        </div>
    </nav>
    <header>
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                </div>
                <div class="col-md-8">
                    <div class="logo">
                        <img class="img-fluid" src="<?php print $site_url; ?>img/logo.png" alt="">
                    </div>
                    <div class="logo-add overflow-hidden">
                        <div class="row">
                            <div class="col-6">
                                <div class="download">
                                    <a href="<?php print $site_url; ?>download">
                                        <div class="btn-custom btn-header-download">
                                            <div class="btn-text-center"><?php print $lang['download']; ?></div>
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="desc">
                                    <p class="title-desc" style="width: 220px; margin-top: 0.7rem;">Play now for free!</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>
    <section class="detailed-section">
        <div class="container">
            <div class="row no-gutters">
                <!-- LEFT_SIDEBAR -->
                <div class="col-lg-3">
                    <div class="login-box">
                        <div class="login-header">
                            <div class="name">
                                <h3><?php print $lang['user-panel']; ?></h3>
                            </div>
                        </div>
                        <div class="login-body-bg">
                            <div class="login-body">
<?php if($offline || !$database->is_loggedin()) { ?>
	<form method="post" action="<?php print $site_url; ?>users/login">
		<div class="form-outline">
			<input type="text" class="form-control mt-3" id="loginUsername" name="username" pattern=".{5,64}" maxlength="64" placeholder="<?php print $lang['user-name-or-email']; ?>" autocomplete="off" <?php if($offline) print 'disabled'; else print 'required'; ?>>
		</div>
		<div class="form-outline">
			<input type="password" class="form-control mt-3" id="loginPassword" name="password" pattern=".{5,16}" maxlength="16" placeholder="<?php print $lang['password']; ?>" <?php if($offline) print 'disabled'; else print 'required'; ?>>
		</div>
		<div class="form-outline">
			<input type="password" class="form-control mt-3" name="pin" pattern=".{4,4}" maxlength="4" class="form-control" placeholder="Pin" <?php if($offline) print 'disabled'; else print 'required'; ?>>
		</div>
		<div class="input-group">
			<center><div class="g-recaptcha" style="margin-top: 15px;" data-theme="dark" data-sitekey="<?php print $site_key; ?>"></div></center>
		</div>
		<div class="login-body-submit">
			<div class="col-6">
				<button class="btn-custom btn-login-box" type="submit">
					<div class="btn-text-center">Log In</div>
				</button>
			</div>
			<div class="col-6">
				<a href="/users/pin" class="btn-custom-pin">Reset Pin</a>
			</div>
		</div>
	</form>
<?php } else { ?>
<div id='account_block' class="col-12">
	<?php if($web_admin) { ?>
	<a href="<?php print $site_url; ?>admin"><?php print $lang['administration']; ?></a>
	<?php 
		if($web_admin>=$jsondataPrivileges['donate']) {
			$count_donations = count(get_donations());
			if($count_donations)
			{
	?>	
	<a href="<?php print $site_url; ?>admin/donatelist"><?php print $lang['donatelist']; ?> <span class="tag tag-info tag-pill float-xs-right"><?php print $count_donations.' '.$lang['new-donations']; ?> </span></a>
	<?php
			}
		}
	}
	?>
	<a href="<?php print $site_url; ?>user/administration"><?php print $lang['account-data']; ?></a>
	<a href="<?php print $site_url; ?>user/characters"><?php print $lang['chars-list']; ?></a>
	<a href="<?php print $site_url; ?>user/redeem"><?php print $lang['redeem-codes']; ?></a>
	<?php if($jsondataFunctions['active-referrals']) { ?>
	<a href="<?php print $site_url; ?>user/referrals"><?php print $lang['referrals']; ?></a>
	<?php } if($item_shop!="") { ?>
	<a target='_blank' href="<?php print $item_shop; ?>"><?php print $lang['item-shop']; ?></a>
	<?php }
		$vote4coins = file_get_contents('include/db/vote4coins.json');
		$vote4coins = json_decode($vote4coins, true);
		
		if(count($vote4coins))
			print '<a href="'.$site_url.'user/vote4coins">Vote4Coins</a>';
		
		$donate = file_get_contents('include/db/donate.json');
		$donate = json_decode($donate, true);
		
		if(count($donate))
			print '<a href="'.$site_url.'user/donate">'.$lang['donate'].'</a>';
	?>
	<a href="<?php print $site_url; ?>users/logout"><?php print $lang['logout']; ?></a>
</div>
<?php } ?>
                            </div>

                        </div>
                    </div>

                    <div class="mb-3"></div>

                    <div class="ranking-box">
                        <div class="login-header">
                            <div class="name">
                                <h3><?php print $lang['ranking'].' '.$lang['players']; ?></h3>
                            </div>
                            <div class="type">
                                <a href="<?php print $site_url; ?>ranking/players">
                                    <h4>Top 100 &raquo;</h4>
                                </a>
                            </div>
                        </div>
                        <div class="ranking-body">
                            <div class="overflow-auto">
                                <table class="table ranking-table">

												<?php
													$top = getJsonSettings("players", "stats5backup");
													
													$i=0;
													
													foreach($top as $player)
													{
														$i++;
														print '<tr>
															<td>'.$i.'.</td>
															<td class="player">'.$player['name'].'</td>
															<td><span class="color-empire-'.$player['empire'].'">'.emire_name($player['empire']).'</span></td>
															<td>Lv. '.$player['level'].'</td>
														</tr>';
													}
												?>
                                </table>
                            </div>

                        </div>
                    </div>

                    <div class="faq-box">
                        <div class="faq-body-bg">
                            <div class="faq-body">
                                <div class="col-md-12">

                                    <div id="faq-accordion">
                                        <div class="card">
                                            <div class="card-header" id="heading-1">
                                                <h5 class="mb-0">
                                                    <button class="btn btn-link" data-toggle="collapse" data-target="#collapse-1" aria-expanded="false" aria-controls="collapse-1">
										How to get rich on <?php print $site_title; ?>?                                    </button>
                                                </h5>
                                            </div>

                                            <div id="collapse-1" class="collapse" aria-labelledby="heading-1" data-parent="#faq-accordion">
                                                <div class="card-body">
                                                    I don't know. </div>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-6" id="custom-content-center">

                    <div class="content-box">
						<?php include 'pages/'.$page.'.php'; ?>
                    </div>

                </div>
                <!-- RIGHT_SIDEBAR -->
                <div class="col-lg-3">
					<?php if(!$offline && $statistics) { ?>
                    <div class="stats-box">
                        <div class="login-header">
                            <div class="name">
                                <h3><?php print $lang['statistics']; ?></h3>
                            </div>
                        </div>
                        <div class="stats-body-bg">
                            <div class="stats-body">
                                <div class="col-md-12">
                                    <div class="server-stats">
                                        <ul>
											<?php
												$statistics_bk=getJsonSettings("stats", "stats5backup");
												$i = false;
												foreach($jsondataFunctions as $key => $status)
													if($key != 'active-registrations' && $key != 'players-debug' && $key != 'active-referrals' && $status)
													{
												?>
                                            <li<?php if(!$i) print ' style="margin-top: unset;"'; ?>>
                                                <span class="type"><?php print $lang[$key]; ?></span>
                                                <span class="value"><?php print number_format($statistics_bk[$key], 0, '', '.'); ?></span>
                                            </li>
											<?php $i = true; } ?>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
					<?php if($jsondataFunctions['players-online-last-24h']) { ?>
                    <div class="players-online">
                        <div class="players-online-bg">
                            <div class="players-online-body">
                                <div class="col-md-12">
                                    <span class="amount"><?php print number_format($statistics_bk['players-online-last-24h'], 0, '', '.'); ?></span>
                                    <span class="main-text"><?php print $lang['players-online']; ?> <span class="twenty-four">(24h)</span></span>
                                </div>
                            </div>
                        </div>
                    </div>
					<?php } } ?>
                    <a href="<?php print $social_links['discord']; ?>" target="_blank">
                        <div class="btn-custom btn-banner-discord">
                            <div class="btn-text-banner-discord-main">Connect Discord</div>
                            <div class="btn-text-banner-discord-second">Join to Our Community!</div>
                        </div>
                    </a>

                    <div class="ranking-box">
                        <div class="login-header">
                            <div class="name">
                                <h3><?php print $lang['ranking'].' '.$lang['guilds']; ?></h3>
                            </div>
                            <div class="type">
                                <a href="<?php print $site_url; ?>ranking/guilds">
                                    <h4>Top 100 &raquo;</h4>
                                </a>
                            </div>
                        </div>
                        <div class="ranking-body">
                            <div class="overflow-auto">
                                <table class="table ranking-table">

												<?php
													$top = getJsonSettings("guilds", "stats5backup");
													
													$i=0;
													
													foreach($top as $guild)
													{
														$i++;
														print '
                                    <tr>
                                        <td>'.$i.'.</td>
                                        <td>'.$guild['name'].'</td>
                                        <td>
                                            <span class="color-empire-'.$guild['empire'].'">'.emire_name($guild['empire']).'</span>
                                        </td>
                                        <td>'.$guild['ladder_point'].'</td>
                                    </tr>';
													}
												?>
                                </table>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </section>

    <footer>
        <div class="first-footer">
            <div class="container">
                <div class="top-footer">
                    <ul>
						<li><a href="<?php print $site_url; ?>news"><?php print $lang['news']; ?></a></li>
						<li><a href="<?php print $site_url; ?>download"><?php print $lang['download']; ?></a></li>
						<?php if(!$database->is_loggedin()) { ?>
						<li><a href="<?php print $site_url; ?>users/register"><?php print $lang['register']; ?></a></li>
						<?php } ?>
						<li><a href="<?php print $site_url; ?>ranking/players"><?php print $lang['ranking']; ?></a></li>
						<li><a href="<?php print $social_links['discord']; ?>" target="_blank">Discord</a></li>
                    </ul>
                </div>

            </div>
        </div>
        <a href="https://www.metin2pserver.info" title="Metin2 P Server">Metin2 P Server</a>
        <div class="second-footer">
            <div class="container">
                <div class="bottom-content">
                    <div class="left-content">
                        <p style="margin-bottom: unset">All rights reserved © <a href="#"><?php print $site_title; ?></a></p>
                    </div>
                    <div class="right-content">
                        <p style="margin-bottom: unset">Design by <a href="https://pixarts.net/" target="_blank">Pixarts.net</a>.
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </footer>
    <!-- Vendor JS Files -->
        <script src="<?php print $site_url; ?>js/jquery-2.2.4.min.js"></script>
	<?php include 'include/functions/footer.php'; ?>
	<script src="<?php print $site_url; ?>assets/jquery/jquery.min.js"></script>
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
    <script src="<?php print $site_url; ?>assets/jquery-easing/jquery.easing.min.js"></script>
</body>