
<?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
31.3 zmena z get na post
  */
#if (session_id() == "") 
 require "files/javamd5.inc.php";
if ((!IsSet($_SESSION['LOGIN'])) OR ($_SESSION['LOGIN']==FALSE))
{      
  //echo(session_id()) ;
  if (IsSet($_POST['submited']))
  {
    include "db_connect.php" ;
    $query="SELECT U.login,UG.Name,U.idUSER 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($uzivatel,$id_group,$id_uzivatel)=mysql_fetch_row($result);
      $_SESSION["LOGIN"] = TRUE;
      $_SESSION["PERMISION"]=$id_group;
      $_SESSION["USER"] = $uzivatel;
      $_SESSION["USERID"] = $id_uzivatel;
      $_SESSION["ACTUALFORM"]=4 ; #vychozi index formulare
      //echo ("to se provadi")  ; 
    }
    else
    { 
        echo ("Login 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="post">
            <table align="center" style="border-width:2px;border-style:solid">
              <tr>
                  <td colspan=2><h3>Billingový systém pro účtování a monitorování hovorů pro PBX Asterisk</h3</td>
              </tr><tr>
                 <td colspan=2 style="text-align:center"><h4>Diplomová práce, Autor: Petr Depiak</h4>
              </tr><tr>
                  <td style="text-align:center">Login: <input type="text" name="PHP_AUTH_USER" value="<?php echo($_POST['PHP_AUTH_USER']);?>"/> </td>
              </tr>
              <tr>
                  <td style="text-align:center">Heslo: <input type="password" id="PASS" name="PHP_AUTH_PW"/> </td>
              </tr><tr>
                  <input type="hidden" name="submited" value="TRUE"/>
                  <td style="text-align:center" colspan=2 ><input type="submit" value="Přihlásit" ></td>
              </tr>
            </table>
      </body>
</html>
<?php 
     }         
} 
?>

 