<?php

/*  Alternate WebKit
(C) 2011-2014 by Alternate Tools
-----------------------------------------------------

File:         login.php
Description:  Login site

*/

    include "../modules/mod_admin.php";
    include "../modules/class_userlist.php";
    
    $errorString = "";
    
    // Check user authorisation?
    if (isset ($_POST['login_Do']))
    {
        $usrList = new cUserList;
        $usrList->SetFolder($USER_FOLDER);
        $loginResult = $usrList->CheckLogin($_POST['login_username'], $_POST['login_password']);
        if ($loginResult == false)
        {
            $errorString = get_translation('admin_login_error');
            log_message ('User ' . $_POST['login_username'] . ' login failed!');
        }
        else
        {
            log_in ($_POST['login_username'], $loginResult);
            log_message ('User ' . $_POST['login_username'] . ' logged in');
            header ('location: ' . $ADMIN_MAIN_SITE);
            return;
        }
    }

    print_admin_header(get_translation('admin_login_head'));
    if ($errorString != "")
        print_error_message($errorString);
        
    echo_r('<div class="admin_login_outer_div">');
    echo_r('<div class="admin_login_div">');
    echo_r('<form method="post" action="">');
    echo_r('  <div class="admin_login_username_div">');
    echo_r('    <div class="admin_login_text_div">' . get_translation('admin_login_username') . '</div>');
    echo_r('    <div class="admin_login_input_div"><input type="text" name="login_username" id="login_username"></div>');
    echo_r('  </div>');
    echo_r('  <div class="admin_clear_float"></div>');
    echo_r('  <div class="admin_login_password_div">');
    echo_r('    <div class="admin_login_text_div">' . get_translation('admin_login_password') . '</div>');
    echo_r('    <div class="admin_login_input_div"><input type="password" name="login_password"></div>');
    echo_r('  </div>');
    echo_r('  <div class="admin_clear_float"></div>');
    echo_r('  <div class="admin_login_bottom_div"><input class="action_btn" type="submit" name="login_Do" value="' . get_translation('admin_login_login') . '"></div>');
    echo_r('</form>');
    echo_r('</div>');
    echo_r('</div>');
    echo_r('<script type="text/javascript" language="JavaScript">');
    echo_r('  document.getElementById(\'login_username\').focus();');
    echo_r('</script>');

    print_admin_footer();
?>