<?php
/**
 * Created by IntelliJ IDEA.
 * User: Christoph
 * Date: 05.02.2018
 * Time: 17:14
 */
session_start();
include('config/config.inc.php');
$data = new Config();

if (empty($_SESSION['status'])) {
    if (!file_exists('config/config.inc.php')) {
        $_SESSION['status'] = 'error';
    } else {
        $_SESSION['status'] = 'login';
    }
}

try {
    $pdo = new PDO('mysql:host=' . $data->getSQLHost() . ';dbname=' . $data->getSQLDatabase() . ';charset=utf8mb4', $data->getSQLUser(), $data->getSQLPassword());
} catch (PDOException $exception) {
    echo "Fehler: " . $exception->getMessage();
    exit;
}


?>
<!doctype html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- Style -->
    <link href="style/css/bootstrap.css" rel="stylesheet">
    <link href="style/css/style.css" rel="stylesheet">
    <link href="style/css/font-awesome.min.css" rel="stylesheet">
    <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet" />
    <link href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" rel="stylesheet" />
    <title>BOS Funk | Login</title>
</head>
<body>
<?php
if ($_SESSION['status'] == 'logged_in') { ?>
    <!-- Dashboard -->
    <div id="content">
        <h1>Willkommen im SH-SRV.info Status ACP
            <a style="float: right" href="scripts/logout.php">
                <button type="button" class="btn btn-default btn-lg"><span class="glyphicon glyphicon glyphicon-log-out" aria-hidden="true"> Logout</span> </button>
            </a>
        </h1>

        <form id="status_message">
            <textarea name="message" placeholder="Meldung" rows="6" minlength="10"></textarea>
            <button class="btn btn-success" type="submit">Absenden</button>
            <button class="btn btn-danger" type="reset">Reset</button>
        </form>
    </div>
<?php } ?>


<?php
if ($_SESSION['status'] == 'login') { ?>
    <div id="particles-js" class="background-site"></div>
    <!--Login Screen-->
    <form id="login_screen_panel" method="POST">
        <p>Willkommen im Status ACP, bitte melden Sie sich an.</p>
        <div class="input-group">
            <span class="input-group-addon glyphicon glyphicon-user" aria-hidden="true"></span>
            <input type="text" class="form-control" name="username" id="username" placeholder="Username">
        </div>

        <p></p>
        <div class="input-group">
            <span class="input-group-addon glyphicon glyphicon-lock" aria-hidden="true"></span>
            <input type="password" class="form-control" id="password" name="password" placeholder="Passwort">
        </div>
        <p></p>
        <button style="width: 75%; text-align: center" type="button" class="btn btn-primary" onclick="checkLogin();"
                name="login" id="login">Login
        </button>
        <p></p>
        <i class="center-text"></i><span id="feedback"></span>
    </form>


<?php } ?>
<!-- Script -->

  <script src="style/js/jQuery.js"></script>
  <script src="style/js/bootstrap.js"></script>
  <script src="style/js/particles.js"></script>
  <script src="style/js/app.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
    <script>

        $("#password").keypress(function (event) {
            if(event.keyCode == 13) {
                $("#login").click();
            }
        });

        function checkLogin() {
            var username = $("#username").val();
            var password = $("#password").val();
            $.ajax({
                url: "scripts/login.php",
                type: "POST",
                data: "username=" + username + "&password=" + password,
                success: function (resp) {
                    $("#feedback").html(resp);
                }
            });
        }

        function ddos() {
            toastr.options = {
                "closeButton": false,
                "debug": false,
                "newestOnTop": true,
                "progressBar": false,
                "positionClass": "toast-top-right",
                "preventDuplicates": false,
                "onclick": null,
                "showDuration": "300",
                "hideDuration": "1000",
                "timeOut": "4000",
                "extendedTimeOut": "1000",
                "showEasing": "swing",
                "hideEasing": "linear",
                "showMethod": "fadeIn",
                "hideMethod": "fadeOut"
            };
            toastr.info("Willkommen im ACP!");
        }


    </script>
</body>
</html>
