<?php

$title = 'Swift Airlines | Login Error';
include $_SERVER["DOCUMENT_ROOT"] . '/swift/core/init.php';
if (empty($_POST) === false) {
    $f_uname = $_POST['f_uname'];
    $f_password = $_POST['f_password'];
    if (empty($f_uname) === true || empty($f_password) === true) {
        $errors[] = 'You need to enter both, the username and the password!';
    } else {
        if (f_exists($f_uname) === false) {
            $errors[] = 'No such user exists! Please register!';
        } else {
            if (f_active($f_uname) === false) {
                $errors[] = 'Please activate your account!';
            } else {
                if (strlen($f_password) > 32) {
                    $errors[] = 'Password too long!';
                }
                $f_login = f_login($f_uname, $f_password);
                if ($f_login === false) {
                    $errors[] = 'Username and Password do not match!';
                } else {
                    $_SESSION['f_id'] = $f_login;
                    header('Location: http://localhost/swift/index.php');
                    exit;
                }
            }
        }
    }
} else {
<?php

ob_start();
session_start();
//error_reporting(0);
require $_SERVER["DOCUMENT_ROOT"] . '/swift/core/database/connect.php';
require $_SERVER["DOCUMENT_ROOT"] . '/swift/core/functions/general.php';
require $_SERVER["DOCUMENT_ROOT"] . '/swift/core/functions/users.php';
$current_file = $_SERVER['SCRIPT_NAME'];
$current_file = explode('/', $current_file);
$current_file = end($current_file);
if (f_logged_in() === true) {
    $session_f_id = $_SESSION['f_id'];
    $f_data = f_data($session_f_id, 'f_id', 'f_uname', 'f_password', 'f_fname', 'f_lname', 'f_address', 'f_phone', 'f_mailid', 'f_sex', 'f_regdate', 'f_passrec');
    if (f_active($f_data['f_uname']) === false) {
        session_destroy();
        header('Location: http://localhost/swift/index.php');
        exit;
    }
    if ($current_file !== 'changepass.php' && $current_file !== 'logout.php' && $f_data['f_passrec'] == 1) {
        header('Location: http://localhost/swift/changepass.php?force');
        exit;
    }
}
$errors = array();