<?php
error_reporting(0);

//lang_varijable
$l_form_desc='Molim unesite korisničko ime i lozinku';
$l_username='Username';
$l_password='Password';
$l_submit='Log in';
$l_error='Neispravno korisničko ime ili lozinka!';
// izvrši skriptu samo ako je forma prosljeđena
if (array_key_exists('login', $_POST)) {
	// start the session
	session_start();
	// include nukeMagicQuotes and clean the $_POST array
	include('func/corefunc.php');
	nukeMagicQuotes();
	//include mysql connection
	include ("func/db_func.php");
	//spoji se na bazu
	$conn = db_connect($mysql_hosname,$mysql_username,$mysql_password,$mysql_database);
	
	//ucitaj vrijednosti za prosljeđene varijable
	$korisnik=$_POST['username'];
	$lozinka=$_POST['lozinka'];
	
	
	$korisnik=str_replace(" ","_",$korisnik);
	$korisnik=addslashes($korisnik);
	
	$lozinka=str_replace(" ","_",$lozinka);	
	$lozinka=addslashes($lozinka);
	
	
	$lozinka=sha1($lozinka);

	//provjeri postoji li korisnik u bazi
	mysql_set_charset('utf8',$conn);

	//$sql99="SELECT id,username from b7_user where binary username='$korisnik' and binary passwd='$lozinka'";
	$sql99="SELECT id,username from b7_user where binary username='$korisnik' and passwd='$lozinka'";
	$rez99=mysql_query($sql99,$conn);
	if ($rez99) $num99=mysql_num_rows($rez99);
	if ($num99==1) 
	{
		$row99=mysql_fetch_array($rez99);	
		$id_user=$row99[0];
		$user_name=$row99[1];
		if ($id_user && $user_name=='') $user_name=$id_user;
	}
	if ($id_user) {
		$_SESSION['authenticated'] = $id_user;
		$_SESSION['user_name'] = $user_name;
		// if the session variable has been set, redirect
		if (isset($_SESSION['authenticated'])) {
			header('Location: glavna.php');
			exit;
		}
	// if the session variable hasn't been set, refuse entry
	} else {
	  $error = $l_error.'<br>Password je: '.$lozinka;
	}	
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WEBADMIN</title>
<script type="text/javascript" src="func/required.js"></script>
<style type="text/css">
<!--
body {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #333333;
	margin:0px;
	padding:0px;
}
#kontejner {
	margin:50px auto;
	width:680px;
	height:384px;
	background-image:url(slike/bg_index.gif);
	background-position:top left;
	background-repeat:no-repeat;
	border:3px solid #e4e4e4;
}
#kontejner form {
	width:350px;
	margin:20px 0px 0px 50px;
	background-color:#d1dae7;
	border:1px solid #a4b7cf;
}
#kontejner form p {
	text-align:right;
	margin:10px 20px 5px 0px; 
}
#kontejner form input.submit {
	background-color:#8c9eb5;
	border:1px solid #a8bad1; 
}
-->
</style>
</head>

<body onload="document.getElementsByTagName('input')[0].focus();">
<div id="kontejner">
<form method="post" action="index.php" enctype="multipart/form-data" onSubmit="return checkrequired(this)">
<fieldset>
<?php
if ($error) {
	?>
	<p><strong style="color:#FF0000;"><?php echo $error; ?></strong></p>
    bllaaaa
	<?php
}
?>
<p><strong><?php echo $l_form_desc; ?></strong>
</p>
<p>
<label for="username"><?php echo $l_username; ?>:</label>
<input type="text" size="20" maxlength="20" name="username" id="required<?php echo $l_username; ?>" />
</p>
<p>
<label for="lozinka"><?php echo $l_password; ?>:</label>
<input type="password" size="20" maxlength="20" name="lozinka" id="required<?php echo $l_password; ?>" />
</p>
<p>
<input name="login" class="submit" type="submit" value="<?php echo $l_submit; ?>" />
</p>
</fieldset>
</form>
<div style="color:#fff; padding:20px 0 30px 50px;">Želite li nas kontaktirati, nazovite na telefon: 098/94 90 776</div>
</div>
</body>
</html>
