<?php ob_start();
$adminPage = 'login';
require("includes/db.php");

if(empty($_SESSION["zalogowany"]))$_SESSION["zalogowany"]=0;
function ShowLogin($komunikat=""){

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
<title>Zaloguj do CMS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex, nofollow" />
<script src="js/standard.js" type="text/javascript"></script>
<link href="css/login.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="contener">

	<a href="/" class="logo"></a>
    <div id="slogan"></div>
 
    
    <div id="form" style="margin-top:93px;">
    	<form class="form"  method="post" action="" >
        <table width="100%" border="0" style="border-collapse:collapse;">
          <tr>
            <td style="padding-left:3px;">Nazwa użytkownika</td>
            <td style="padding-left:3px;">Hasło</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><label>
              <input name="login" type="text" class="input" id="textfield"  />
            </label></td>
            <td><label>
              <input name="haslo" type="password" class="input" id="textfield2"  />
            </label></td>
            <td><label>
              <input type="image" name="imageField" id="imageField" src="gfx/go.gif" />
            </label></td>
          </tr>
          <tr>
            <td colspan="3"
						<? if($komunikat) { ?>style="padding-top:12px;"><strong style="color:#FF0000;"><?=$komunikat?></strong>
						<? } else echo 'style="padding-top:25px;">'; ?>
            <p>Do prawidłowego działania panelu administracyjnego zalecamy: </p>
              <ol>
                <li>Korzystanie z przeglądarki Mozilla FireFox</li>
                <li>Obsługa Javascript musi być włączona. </li>
                <li>&quot;Cookies&quot; muszą być włączone.</li>
            </ol></td>
          </tr>
        </table>
        </form>
  </div>
    
    
    <div id="footer">&copy; Copyright 2014</div>
    
</div>
</body>
</html>




<?php
	
}

?>


  <?php
if($_GET["wyloguj"]=="tak")
{
	$_SESSION["zalogowany"]=$_SESSION["ediso"]=0;
}

if($_SESSION["zalogowany"]!=1)
{	
	if(!empty($_POST["login"]) && !empty($_POST["haslo"])){
	
	$sql = "select * from users where user_login = '".htmlspecialchars($_POST["login"])."' AND user_haslo = '".md5($_POST["haslo"])."'";

	$result = mysql_query($sql) or die(mysql_error());
	
	if(mysql_num_rows($result)>0){
		
	    
		$row = mysql_fetch_array($result); 		 
		
 		mysql_query("UPDATE users SET ostatnio_zalogowany=NOW() WHERE id=$row[id] ");
		
			$_SESSION["zalogowany"]=1;
			$_SESSION["user_id"]=$row['id'];
			$_SESSION["user_login"]=$row['user_login'];
			$_SESSION["cms_nazwa"]=$row['nazwa'];
			$_SESSION["chmod"]=$row['chmod'];

		
		
			/* echo "<script type='text/javascript'>window.parent.location.href='index.php'</script>"; */
			
			
echo $referer=$_GET['referer'];
	
	if($referer){
		
		header("Location: {$referer}");
		
		} else {
		
		require("index2.php");
	
	}			
			
			 
			}
		else echo ShowLogin("Podano złe dane!");
		
		}
	else ShowLogin();
}
else{
?>
<?php 


		
		require("index2.php");
	
	
?>

  <?php
  
  ob_end_flush();
}
?>