<?
  include_once("config.php");

  $link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die ("Could not connect");

  @mysql_select_db(DB_NAME, $link);
  
  function login_step1() {
include_once("main_header.php");
?>
<center><h1>Login</h1></center>
<form action="login.php?step=2" method="post">
<table width="100%">
 <tr>
  <td width="10%">
  </td>
  <td width="30%" valign="top" align="right">
   Username:<br>
  </td>
  <td>
   <input type="text" name="username" size="30">
  </td>
 </tr>
</table>
<center><br><input type="submit" value="  Enter  "></center>
</form>
<? include_once("main_footer.php");
    return(0);
  }

  function login_step2() {
    global $link;
    global $sitemainhost;
    global $sitedomain;

    $username = htmlspecialchars($_POST['username']);

    if ("" == $username) {
      echo "You must fill username field";
      login_step1();
      return(12);
    }

    $r=mysql_query("select * from blogusers where username='".mysql_escape_string($username)."'",$link);
    if (!mysql_num_rows($r)) {
     
      login_step1();
      return(13);
    }

    header("Location: http://".$sitemainhost.$sitedomain."/".$username."/admin.php");

    return(0);
  }


  if (isset($_GET['step'])) {
    login_step2();
  }
  else {
    login_step1();
  }  

?>