<?
session_start();
include "../inc/db.php";
	$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
	$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
	$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
	$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
	$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");

	if ($iphone || $android || $palmpre || $ipod || $berry == true)
	{
		header('Location: ../mobile/login.php');
	}	
	
if(isset($_POST['submit'])){
	if($_POST['username']==NULL || $_POST['parola']==NULL)
		$eroare = "Wrong Username/Password!";
	else{
		$res	= mysql_query("select (Select value from config where name='admin_pass') as admin_pass,(Select value from config where name='admin_user') as admin_user ")or die('Mysql Error:'.mysql_error());
		$row    = mysql_fetch_array($res);

		if($_POST['username']!=$row['admin_user'] || $_POST['parola']!=$row['admin_pass'])
			$eroare = "Wrong Username/Password!";

		if(empty($eroare)){
			$_SESSION['logged']=1;
			header("Location: ../index.php"); 
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Login Pro Invoice Maker</title>
	<link rel="stylesheet" type="text/css" href="css/login.css" media="screen"/>
</head>
<body>

		<div id="container2">
			<div id="container">
				<div class='header'>Pro Invoice Maker Login</div>
				<div class="content">
					<?php if($eroare){?><div class='error'><?=$eroare?></div><?}?>
						<form action='' method='POST'>			
							<table width='100%' cellspacing='0' cellpadding='0'>
								<tr>
									<td><img src='css/login.png'/></td>
									<td>
										<label for='username'>Username</label>
										<input type='text' class='login' name='username' id='username' value=''/>								
										
										<label for='parola'>Password</label>
										<input type='password' class='login' name='parola' id='parola' value=''/>
										<input type='submit' name='submit' class='autentificare' value='Login'/>
									</td>
								</tr>
							</table>
						</form>					
					<div class='warning'>
					Your <b>IP</b> is: <b style='color:red;'><?=$_SERVER['REMOTE_ADDR']?></b>
					</div>
				</div>			
			</div>
		</div>
</body>
</html>