<?php include_once("config.inc.php");
session_name('SpeedTest'); session_set_cookie_params(0,'/','',false);
session_start(); header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
?>
<html>
<head>
	<title><?php echo $isp_name; ?> - Speed Test - Admin</title>
	<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
	<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Speed Test - Admin</h1><br>

<?php
if ($_POST['action'] == 'logout')
	{
	$_SESSION['name']='';
	$_SESSION['pass']='';
	session_destroy();
	}

if (($_POST['name'] != '') && ($_POST['pass'] != ''))
	{
	$_SESSION['name'] = $_POST['name'];
	$_SESSION['pass'] = $_POST['pass'];
	}
if (($_SESSION['name'] != $admin_name) ||
	($_SESSION['pass'] != $admin_pass))
	{
	echo '<h2>Prosím, zadejte své přihlašovací údaje.</h2>
	<form action="'.$_SERVER['PHP_SELF'].'" method="POST">
	<table><tr>
	<td width="50">Jméno:</td>
	<td><input class=query type="text" name="name" size="25"></td>
	<td width="40">&nbsp;</td>
	</tr><tr>
	<td>Heslo:</td>
	<td><input class=query type="password" name="pass" size="25"></td>
	<td width="40">&nbsp;</td>
	</tr><tr>
	<td colspan="3" align="right"><input class="button" type="submit" value=" OK "></td>
	</tr></table></form>';
	exit;
	
	} else { // jsme lognuti
	if ($mysql == false)
		{die ('MYSQL database access disabled by configuration.');}

	$table_color_1 = '444444';
	$table_color_2 = '333333';

	$link = mysql_connect($database["host"], $database["login"], $database["password"])
    	or die(mysql_error());
	mysql_select_db($database["database"])
    	or die(mysql_error());
	
	if ($_POST['action'] == 'delete_all')
		{
		$query = 'TRUNCATE TABLE `readings`;';
		$result = mysql_query($query) or die(mysql_error());
		}
	$orderedby = $_GET['orderby'];
	if (($orderby != 'date') &&
		($orderby != 'down') &&
		($orderby != 'speed') &&
		($orderby != 'ip') &&
		($orderby != 'name') &&
		($orderby != 'browser'))
		{$orderby = 'date';}
	
	if ($_GET['asc'] == '0')
		{$asc = 'DESC';} else
		{$asc = 'ASC';}
	
	$query = 'SELECT * FROM `readings` ORDER BY `'.$orderby.'` '.$asc.';';
	$result = mysql_query($query) or die(mysql_error());

	$thisphp = $_SERVER['PHP_SELF'];
	echo '<table width="100%" align="center">
		<tr bgcolor="#'.((! $color2) ? $table_color_1 : $table_color_2).'">
		<td align="center" width="4%">#</td>
		<td align="center"><b><a href="'.$thisphp.'?orderby=date&amp;asc='.((($orderby=='date')&&($asc=='ASC'))?'0':'1').'">Datum/čas</a></b></td>
		<td align="center"><b><a href="'.$thisphp.'?orderby=down&amp;asc='.((($orderby=='down')&&($asc=='ASC'))?'0':'1').'">Směr</a></b></td>
		<td align="center"><b><a href="'.$thisphp.'?orderby=speed&amp;asc='.((($orderby=='speed')&&($asc=='ASC'))?'0':'1').'">Rychlost</a></b></td>
		<td align="center"><b><a href="'.$thisphp.'?orderby=ip&amp;asc='.((($orderby=='ip')&&($asc=='ASC'))?'0':'1').'">IP</a></b></td>
		<td align="center"><b><a href="'.$thisphp.'?orderby=name&amp;asc='.((($orderby=='name')&&($asc=='ASC'))?'0':'1').'">DNS název</a></b></td>
		<td align="center"><b><a href="'.$thisphp.'?orderby=browser&amp;asc='.((($orderby=='browser')&&($asc=='ASC'))?'0':'1').'">Prohlížeč</a></b></td>
		</tr>';

	$i=0;
	$color2 = true;
	while ($item = mysql_fetch_assoc($result))
		{
		$i++;
		$color2 = ! $color2;
		echo '<tr bgcolor="#'.(($color2) ? $table_color_1 : $table_color_2).'"><td>'.
						$i.'</td><td>'.
						$item['date'].'</td><td>'.
						$item['down'].'</td><td>'.
						$item['speed'].'</td><td>'.
						$item['ip'].'</td><td>'.
						$item['name'].'</td><td>'.
						$item['browser'].'</td></tr>'."\n";
		}
	echo '</table><br><br>';
 
	echo '<table width="100%"><tr>
	<td align="center"><form action="'.$thisphp.'?orderby='.$orderby.'&amp;asc='.$_GET['asc'].'" method="POST">
	<input name="action" type="hidden" value="reload">
	<input class="button" type="submit" value="Obnovit"></form></td>
	<td align="center"><form action="'.$thisphp.'" method="POST">
	<input name="action" type="hidden" value="delete_all">
	<input class="button" type="submit" value="Smazat vše"></form></td>
	<td align="center"><form action="'.$thisphp.'" method="POST">
	<input name="action" type="hidden" value="logout">
	<input class="button" type="submit" value="Odhlásit se"></form></td>
	</tr></table>';
	
	}

?>

</body>
</html>
