<?php
/*
 * @ https://EasyToYou.eu - IonCube v10 Decoder Online
 * @ PHP 5.6
 * @ Decoder version: 1.0.4
 * @ Release: 02/06/2020
 *
 * @ ZendGuard Decoder PHP 5.6
 */

require "include/connection.php";
$error = false;
if (isset($_POST["a"])) {
    $valid = false;
    if (!isset($_POST["login"]) || strlen($_POST["login"]) == 0) {
        $error = "Please enter your user name";
    } else {
        if (!isset($_POST["pass"]) || strlen($_POST["pass"]) == 0) {
            $error = "Please enter your password";
        } else {
            $getuser = mysqli_query($link, "SELECT * FROM `users` WHERE `username`='" . $_POST["login"] . "'");
            if (0 < mysqli_num_rows($getuser)) {
                $row = mysqli_fetch_array($getuser);
                $hashed_password = $row["password"];
                $user_role = $row["user_role"];
                if (!empty($row["startpage"])) {
                    $redirect = $row["startpage"] . $row["query_string"];
                } else {
                    $getredirect = mysqli_query($link, "SELECT `start_file` FROM `user_roles` WHERE `user_role_id`='" . $user_role . "'");
                    $getredirectrow = mysqli_fetch_array($getredirect);
                    $redirect = $getredirectrow["start_file"];
                }
                if (password_verify($_POST["pass"], $hashed_password)) {
                    $valid = true;
                } else {
                    $error = "Wrong user/password, please try again";
                }
            } else {
                $error = "Wrong user/password, please try again";
            }
        }
    }
    $ajax = isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest";
    if ($valid) {
        if (isset($_POST["keep-logged"]) && $_POST["keep-logged"] == 1) {
            setcookie("user_id", $row["id"], time() + 3600);
            setcookie("username", $row["username"], time() + 3600);
            setcookie("user_role", $row["user_role"], time() + 3600);
        }
        if ($ajax) {
            header("Cache-Control: no-cache, must-revalidate");
            header("Expires: " . date("r", time() + 86400 * 365));
            header("Content-type: application/json");
            echo json_encode(array("valid" => true, "redirect" => $redirect));
            exit;
        }
        header("Location: " . $redirect);
        exit;
    }
    if ($ajax) {
        header("Cache-Control: no-cache, must-revalidate");
        header("Expires: " . date("r", time() + 86400 * 365));
        header("Content-type: application/json");
        echo json_encode(array("valid" => false, "error" => $error));
        exit;
    }
}
if ($_REQUEST["logout"] == "yes") {
    setcookie("username", "", time() - 3600);
    setcookie("user_role", "", time() - 3600);
    header("Location: login.php");
    exit;
}
echo "<!doctype html>\n<!--[if lt IE 8 ]><html lang=\"en\" class=\"no-js ie ie7\"><![endif]-->\n<!--[if IE 8 ]><html lang=\"en\" class=\"no-js ie\"><![endif]-->\n<!--[if (gt IE 8)|!(IE)]><!--><html lang=\"en\" class=\"no-js\"><!--<![endif]-->\n<head>\n\t<meta charset=\"UTF-8\">\n\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n\t\n\t<title>XC Management Login</title>\n\t<meta name=\"description\" content=\"\">\n\t<meta name=\"author\" content=\"\">\n\t\n\t<!-- Combined stylesheets load -->\n\t<link href=\"css/mini.php?files=reset,common,form,standard,special-pages\" rel=\"stylesheet\" type=\"text/css\">\n\t\n\t<!-- Favicon -->\n\t<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"favicon.ico\">\n\t<link rel=\"icon\" type=\"image/png\" href=\"favicon-large.png\">\n\t\n\t<!-- Modernizr for support detection, all javascript libs are moved right above </body> for better performance -->\n\t<script src=\"js/libs/modernizr.custom.min.js\"></script>\n\t\n</head>\n\n<!-- the 'special-page' class is only an identifier for scripts -->\n<body class=\"special-page login-bg dark\">\n\t\n\t<section id=\"login-block\">\n\t\t<div class=\"block-border\"><div class=\"block-content\">\n\t\t\t\n\t\t\t<!--\n\t\t\tIE7 compatibility: if you want to remove the <h1>,\n\t\t\tadd style=\"zoom:1\" to the above .block-content div\n\t\t\t-->\n\t\t\t<h1>XC</h1>\n\t\t\t<div class=\"block-header\">Please login</div>\n\t\t\t\t\n\t\t\t";
if ($error) {
    echo "<p class=\" error no-margin\">";
    echo htmlspecialchars($error);
    echo "</p>\n\t\t\t\n\t\t\t";
}
echo "<form class=\"form with-margin\" name=\"login-form\" id=\"login-form\" method=\"post\" action=\"\">\n\t\t\t\t<input type=\"hidden\" name=\"a\" id=\"a\" value=\"send\">\n\t\t\t\t<p class=\"inline-small-label\">\n\t\t\t\t\t<label for=\"login\"><span class=\"big\">User name</span></label>\n\t\t\t\t\t<input type=\"text\" name=\"login\" id=\"login\" class=\"full-width\" value=\"";
if (isset($_POST["login"])) {
    echo htmlspecialchars($_POST["login"]);
}
echo "\">\n\t\t\t\t</p>\n\t\t\t\t<p class=\"inline-small-label\">\n\t\t\t\t\t<label for=\"pass\"><span class=\"big\">Password</span></label>\n\t\t\t\t\t<input type=\"password\" name=\"pass\" id=\"pass\" class=\"full-width\" value=\"\">\n\t\t\t\t</p>\n\t\t\t\t\n\t\t\t\t<button type=\"submit\" class=\"float-right\">Login</button>\n\t\t\t\t<p class=\"input-height\">\n\t\t\t\t\t<input type=\"checkbox\" name=\"keep-logged\" id=\"keep-logged\" value=\"1\" class=\"mini-switch\"";
if (!isset($_POST["keep-logged"]) || $_POST["keep-logged"] == 1) {
    echo " checked=\"checked\"";
}
echo ">\n\t\t\t\t\t<label for=\"keep-logged\" class=\"inline\">Keep me logged in</label>\n\t\t\t\t</p>\n\t\t\t</form>\n\t\t\t\n\t\t\t<form class=\"form\" id=\"password-recovery\" method=\"post\" action=\"\">\n\t\t\t\t<fieldset class=\"grey-bg no-margin collapse\">\n\t\t\t\t\t<legend><a href=\"#\">Lost password?</a></legend>\n\t\t\t\t\t<p class=\"input-with-button\">\n\t\t\t\t\t\t<label for=\"recovery-mail\">Enter your e-mail address</label>\n\t\t\t\t\t\t<input type=\"text\" name=\"recovery-mail\" id=\"recovery-mail\" value=\"\">\n\t\t\t\t\t\t<button type=\"button\">Send</button>\n\t\t\t\t\t</p>\n\t\t\t\t</fieldset>\n\t\t\t</form>\n\t\t</div></div>\n\t</section>\n\t\n\t<!--\n\t\n\tUpdated as v1.5:\n\tLibs are moved here to improve performance\n\t\n\t-->\n\t\n\t<!-- Combined JS load -->\n\t<script src=\"js/mini.php?files=libs/jquery-1.6.3.min,old-browsers,common,standard,jquery.tip\"></script>\n\t<!--[if lte IE 8]><script src=\"js/standard.ie.js\"></script><![endif]-->\n\t\n\t<!-- example login script -->\n\t<script>\n\t\n\t\t\$(document).ready(function()\n\t\t{\n\t\t\t// We'll catch form submission to do it in AJAX, but this works also with JS disabled\n\t\t\t\$('#login-form').submit(function(event)\n\t\t\t{\n\t\t\t\t// Stop full page load\n\t\t\t\tevent.preventDefault();\n\t\t\t\t\n\t\t\t\t// Check fields\n\t\t\t\tvar login = \$('#login').val();\n\t\t\t\tvar pass = \$('#pass').val();\n\t\t\t\t\n\t\t\t\tif (!login || login.length == 0)\n\t\t\t\t{\n\t\t\t\t\t\$('#login-block').removeBlockMessages().blockMessage('Please enter your user name', {type: 'warning'});\n\t\t\t\t}\n\t\t\t\telse if (!pass || pass.length == 0)\n\t\t\t\t{\n\t\t\t\t\t\$('#login-block').removeBlockMessages().blockMessage('Please enter your password', {type: 'warning'});\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvar submitBt = \$(this).find('button[type=submit]');\n\t\t\t\t\tsubmitBt.disableBt();\n\t\t\t\t\t\n\t\t\t\t\t// Target url\n\t\t\t\t\tvar target = \$(this).attr('action');\n\t\t\t\t\tif (!target || target == '')\n\t\t\t\t\t{\n\t\t\t\t\t\t// Page url without hash\n\t\t\t\t\t\ttarget = document.location.href.match(/^([^#]+)/)[1];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t// Request\n\t\t\t\t\tvar data = {\n\t\t\t\t\t\ta: \$('#a').val(),\n\t\t\t\t\t\tlogin: login,\n\t\t\t\t\t\tpass: pass,\n\t\t\t\t\t\t'keep-logged': \$('#keep-logged').attr('checked') ? 1 : 0\n\t\t\t\t\t};\n\t\t\t\t\t\n\t\t\t\t\t// Start timer\n\t\t\t\t\tvar sendTimer = new Date().getTime();\n\t\t\t\t\t\n\t\t\t\t\t// Send\n\t\t\t\t\t\$.ajax({\n\t\t\t\t\t\turl: target,\n\t\t\t\t\t\tdataType: 'json',\n\t\t\t\t\t\ttype: 'POST',\n\t\t\t\t\t\tdata: data,\n\t\t\t\t\t\tsuccess: function(data, textStatus, XMLHttpRequest)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (data.valid)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// Small timer to allow the 'cheking login' message to show when server is too fast\n\t\t\t\t\t\t\t\tvar receiveTimer = new Date().getTime();\n\t\t\t\t\t\t\t\tif (receiveTimer-sendTimer < 500)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tsetTimeout(function()\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tdocument.location.href = data.redirect;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t}, 500-(receiveTimer-sendTimer));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tdocument.location.href = data.redirect;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// Message\n\t\t\t\t\t\t\t\t\$('#login-block').removeBlockMessages().blockMessage(data.error || 'An unexpected error occured, please try again', {type: 'error'});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tsubmitBt.enableBt();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror: function(XMLHttpRequest, textStatus, errorThrown)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// Message\n\t\t\t\t\t\t\t\$('#login-block').removeBlockMessages().blockMessage('Error while contacting server, please try again', {type: 'error'});\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tsubmitBt.enableBt();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\t// Message\n\t\t\t\t\t\$('#login-block').removeBlockMessages().blockMessage('Please wait, cheking login...', {type: 'loading'});\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\n\t</script>\n\t\n</body>\n</html>\n";

?>