<?php
	$currentDate = date("Y, n, j, G, i, s");
	
	session_start();
	
	// why does this always unsave itself lmao
	
	if (!isset($_SESSION['logged_in']))
	{
		$_SESSION['logged_in'] = false;	
	}
?>
<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>Anonymous Games</title>
    
    <link rel="stylesheet" type="text/css" href="css/utility.css">
    <link rel="stylesheet" type="text/css" href="css/main.css">
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.2/modernizr.js"></script>
    <script src="scripts/easySlider1.7.js"></script>
    <script src="scripts/time.js"></script>
    <script src="scripts/functions.js"></script>
</head>
<body onload="showTime();">
	<div id="bb">
    	<div id="wrapper">
        	<div class="wrapper">
            	<div id="header">
                	<div id="navbar">
                    	<ul>
                        	<?php include ("inc/sitenav.php");?>
                        </ul>
                    </div>
                </div>
            </div>
            <div id="bptop"></div>
            <div id="bpcon">
            	<div class="wrapper confix">
                	<div id="content">
                    	<div class="cui ctop"></div>
                        <div class="cui ccon">
                        	<div class="clearfix"></div>
                            <?php include ("inc/slider.php");?>
                            <div class="cbox-ui cbox-title">
                            	<h2>
                                	<a href="ranking.php">Top Players</a>|<a href="../topguilds.php">Top Guilds</a>|<a class="link" href="create.php">Newest Characters</a>
                                </h2>
                            </div>
                            <div class="cbox-ui cbox-content">
                            	<div class="clearfix"></div>
                                <center>
                                	<?php
										if ($_SESSION['logged_in'] == true)
										{
                                			include ("inc/cashShop.php");
										}
										else {
											include ("inc/loginForm.php");	
										}
									?>
                                </center>
                            </div>
                            <div class="cbox-ui cbox-end"></div>
                            <div class="clearfix"></div>
                        </div>
                        <div class="cui cbottom"></div>
                    </div>
                    <div id="sidebar">
                    	<a class="download" href="#">
                        	<span>Client Download</span>
                            <small>Anonymous Games Setup (8.2 GB)</small>
                        </a>
                        <div class="clear"></div>
                        <div class="sbox">
                        	<div class="sbui sb-title">
                            	<img alt="Current Stats" src="http://cdn.exine.co/StormyCP/img/stats.png" />
                                <h4>Server Time</h4>
                            </div>
                            <div class="sbui sb-con">
                            	<div class="time">
                                	<div id="clockbox"><span id="currentTime" class="time"></span></div>
                                    <!-- Time Script, don't worry about this -->
                                    <script language="JavaScript">
									<!--
									var serverTime = new Date(<?php echo $currentDate; ?>);
									function showTime()
									{
									if(!document.all && !document.getElementById)
									{
									return;
									}
									var Hours = serverTime.getHours();
									var Minutes = serverTime.getMinutes();
									var Seconds = serverTime.getSeconds();
									serverTime.setSeconds(Seconds+1);
									if(Hours <= 9)
									{
									Hours = "0" + Hours;
									}
									if(Minutes <= 9)
									{
									Minutes = "0" + Minutes;
									}
									if(Seconds <= 9)
									{
									Seconds = "0" + Seconds;
									}
									var parsedTime = Hours + ":" + Minutes + ":" + Seconds;
									if(document.getElementById)
									{
									document.getElementById("currentTime").innerHTML = parsedTime
									}
									else if(document.all)
									{
									Time.innerHTML = parsedTime;
									}
									setTimeout("showTime()", 1000);
									}
									//-->
									</script>
                                    <!-- End of time script -->
                                </div>
                            </div>
                            <div class="sbui sbft"></div>
                        </div>
                        <div class="clear"></div>
                        <div class="sbox">
                        	<div class="sbui sb-title">
                            	<img alt="Player Ranking" src="http://cdn.exine.co/StormyCP/img/ranking.png" />
                                <h4>Top Players</h4>
                            </div>
                            <div class="sbui sb-con">
                            	<?php
									$HOST = '184.168.194.75';
									$UID = 'Mars';
									$PWD = 'ExineAdmin1#27';
									$DB = 'StormyTest';
									
									$connectionInfo = array( "Database"=>$DB, "UID"=>$UID, "PWD"=>$PWD);
									$conn = sqlsrv_connect( $HOST, $connectionInfo);
									
									if ($conn)
									{
										$topQuery = "SELECT TOP 5 sID, nLevel, nFame FROM tCharacter WHERE nAdminLevel=0 AND bDeleted=0";
										$doTopQuery = sqlsrv_query($conn, $topQuery);
										if ($doTopQuery)
										{
											$i = 1;
											echo '<table id="sbRanking" width="90%" border="0" cellspacing="0" cellpadding="0">';
											echo '<tr><td>#</td><td>Name</td><td>Level</td></tr>';
											while($player = sqlsrv_fetch_array($doTopQuery))
											{
												$player["sID"] = str_replace("ä", "&auml;", str_replace("Ä", "&Auml;", str_replace("ö", "&ouml;", str_replace("Ö", "&Ouml;", str_replace("ü", "&uuml;", str_replace("Ü", "&Uuml;", str_replace("ß", "&szlig;", $player["sID"])))))));
												echo '<tr><td width="20px">'.$i.'</td><td>'.$player['sID'].'</td><td>'.$player['nLevel'].'</td></tr>';
												$i++;
											}
											echo '</table>';
										}
										else {
											echo '<div class="info">Sorry. The top players list is currently offline</div>';
										}
									}
									else {
										echo '<div class="info">Sorry. The top players list is currently offline</div>';
									}
								?>
                            </div>
                            <div class="sbui sbft"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>