
<?php
/* Formular prihlaseni ver 1.0
Form kotroluje prom. $_SESSION['LOGIN']. Pokud neexistuje, tak je vykonan formular-
Jestli je vykonavan formular, nejprve je zpristupnen form pro vyplneni udaju a 
po potvrzeni je vykonana kantrola s databazi
  */
#if (session_id() == "") 
require "files/javamd5.inc.php";
if ((!IsSet($_SESSION['LOGIN'])) OR ($_SESSION['LOGIN']==FALSE))
{      
  //echo(session_id()) ;
  if (IsSet($_POST['submited']))
  {
    include "build/db_connect.inc.php" ;
    $query="SELECT U.login,UG.Name FROM user U
            JOIN spec_user_group SUG ON U.idUSER=SUG.idUSER
            JOIN user_group UG ON UG.idUSERGROUP=SUG.idUSERGROUP  
            WHERE login LIKE \"".$_POST["PHP_AUTH_USER"]."\"
            AND password LIKE \"".$_POST["PHP_AUTH_PW"]."\" ";
    $result = mysql_query($query);
    if (!$result) {
      die('Could not query:' . mysql_error());
    }
    echo mysql_result($result, 2); 
    //echo  (mysql_num_rows($result) );
    if (mysql_num_rows($result)!=0){
      list($id_uzivatel,$id_group)=mysql_fetch_row($result);
      $_SESSION["LOGIN"] = TRUE;
      $_SESSION["PERMISION"]=$id_group;
      $_SESSION["USER"] = $id_uzivatel;
      $_SESSION["ACTUALFORM"]="Mainpage" ;
      //echo ("to se provadi")  ; 
    }
    else
    { 
        echo ("Jméno nebo heslo je chybné!")  ;
    }  
    //echo ("Sesion user id is: ".$_SESSION["USER"])  ;        
    }
    if ((!IsSet($_SESSION['LOGIN'])) OR ($_SESSION['LOGIN']==FALSE))
    {
?>
<html>
  <head>            
      <meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <meta name="generator" content="PSPad editor, www.pspad.com">
      <title>Přihlášení do systému</title>
  </head> 
      <body>
<script language="JavaScript">
    function Passwarn(){
      document.getElementById('PASS').value=MD5(document.getElementById('PASS').value);
    }
</script>
          <form action="index.php" OnSubmit="Passwarn()" method="get">
            <table align="center">
              <tr>
                  <td>Login:</td><td><input type="text" name="PHP_AUTH_USER" value="<?php echo($_POST['PHP_AUTH_USER']);?>"> </td>
              </tr>
              <tr>
                  <td>Heslo:</td><td><input type="password" id="PASS" name="PHP_AUTH_PW"> </td>
              </tr>
              <tr>
   
          <input type="hidden" name="submited" value="TRUE">
                  <td><input type="submit" value="Přihlásit" ></td>
              </tr>
            </table>
      </body>
</html>
<?php 
     }         
} 
?>

 