{include file="./index_top.tpl"}
<script type="text/javascript">
    var stepData = {};

    function exec_status() {
        var stWidth = $("#analysis_bar").width();
        var stProcess = Math.round((stWidth / 200) * 100);
        if (stProcess == 100) {
            clearInterval(st_init);
            document.getElementById("analysis_status").innerHTML = "<img src='images/indicator.gif' alt='' style='vertical-align: middle' /> " + lang.calc_perf_index + "...";
        }
        return stProcess + "%";
    }

    function exec_step(step) {
        document.getElementById("analysis_status").innerHTML = "<img src='images/indicator.gif' alt='' style='vertical-align: middle' /> " + lang.Work_in + " " + step + " " + lang.from + " 2...";
        if (step == 1) {
            stepData = {};
            stepData[1] = {};
            stepData[2] = {};
            stepData[3] = {};
            stepData[4] = {};
            perfomanceIndex = {};
            document.getElementById("analysis_process").style.visibility = "visible";
            document.getElementById("full_check_button").style.display = "none";
            $("#analysis_bar").animate({ width: "100%" }, 63000, 'linear');
            document.getElementById('analysis_progress').innerHTML = "0%"
            st_init = setInterval("document.getElementById('analysis_progress').innerHTML = exec_status()", 1000);
        }

        $.ajax({
            cache: false,
            type: "POST",
            url: "edit_check.php",
            data: { step: step, csrf: '{$csrf}', stream: '1' },
            success: function (msg) {
                stepData[1][step] = parseInt(msg);
                if (step == 2)
                    perfomanceIndex[1] = (stepData[1][1] + stepData[1][2]) / 2;

                if (stepData[1][step] && stepData[2][step] && stepData[3][step] && stepData[4][step]) {
                    if (step != 2)
                        exec_step(step + 1);
                    else {
                        document.getElementById("analysis_status").innerHTML = "<img src='images/well.gif' alt='' style='vertical-align: middle' /> " + lang.Done;
                        var perfomanceIndexAmount = ((perfomanceIndex[1] + perfomanceIndex[2] + perfomanceIndex[3] + perfomanceIndex[4]) / 4).toFixed(2)
                        document.getElementById("analysis_report").innerHTML = lang.Perfomance_index + ": " + perfomanceIndexAmount;
                    }
                }
            }
        });

        $.ajax({
            cache: false,
            type: "POST",
            url: "edit_check.php",
            data: { step: step, csrf: '{$csrf}', stream: '2' },
            success: function (msg) {
                stepData[2][step] = parseInt(msg);
                if (step == 2)
                    perfomanceIndex[2] = (stepData[2][1] + stepData[2][2]) / 2;

                if (stepData[1][step] && stepData[2][step] && stepData[3][step] && stepData[4][step]) {
                    if (step != 2)
                        exec_step(step + 1);
                    else {
                        document.getElementById("analysis_status").innerHTML = "<img src='images/well.gif' alt='' style='vertical-align: middle' /> " + lang.Done;
                        var perfomanceIndexAmount = ((perfomanceIndex[1] + perfomanceIndex[2] + perfomanceIndex[3] + perfomanceIndex[4]) / 4).toFixed(2)
                        document.getElementById("analysis_report").innerHTML = lang.Perfomance_index + ": " + perfomanceIndexAmount;
                    }
                }
            }
        });

        $.ajax({
            cache: false,
            type: "POST",
            url: "edit_check.php",
            data: { step: step, csrf: '{$csrf}', stream: '3' },
            success: function (msg) {
                stepData[3][step] = parseInt(msg);
                if (step == 2)
                    perfomanceIndex[3] = (stepData[3][1] + stepData[3][2]) / 2;

                if (stepData[1][step] && stepData[2][step] && stepData[3][step] && stepData[4][step]) {
                    if (step != 2)
                        exec_step(step + 1);
                    else {
                        document.getElementById("analysis_status").innerHTML = "<img src='images/well.gif' alt='' style='vertical-align: middle' /> " + lang.Done;
                        var perfomanceIndexAmount = ((perfomanceIndex[1] + perfomanceIndex[2] + perfomanceIndex[3] + perfomanceIndex[4]) / 4).toFixed(2)
                        document.getElementById("analysis_report").innerHTML = lang.Perfomance_index + ": " + perfomanceIndexAmount;
                    }
                }
            }
        });

        $.ajax({
            cache: false,
            type: "POST",
            url: "edit_check.php",
            data: { step: step, csrf: '{$csrf}', stream: '4' },
            success: function (msg) {
                stepData[4][step] = parseInt(msg);
                if (step == 2)
                    perfomanceIndex[4] = (stepData[4][1] + stepData[4][2]) / 2;

                if (stepData[1][step] && stepData[2][step] && stepData[3][step] && stepData[4][step]) {
                    if (step != 2)
                        exec_step(step + 1);
                    else {
                        document.getElementById("analysis_status").innerHTML = "<img src='images/well.gif' alt='' style='vertical-align: middle' /> " + lang.Done;
                        var perfomanceIndexAmount = ((perfomanceIndex[1] + perfomanceIndex[2] + perfomanceIndex[3] + perfomanceIndex[4]) / 4).toFixed(2)
                        document.getElementById("analysis_report").innerHTML = lang.Perfomance_index + ": " + perfomanceIndexAmount;
                    }
                }
            }
        });

    }
</script>
<div align=center>
    <br>{$lang.Sys_check}<span class='help_bt' h_id='Sys_check'></span><br><br>
    {if $checks|count_cb}
        <table>
            {foreach $checks as $check_type=>$one_check}
                {foreach $one_check as $check_name=>$check_info}
                    <tr>
                        <td>{$check_info.description} <a href='{$check_info.help_url}' target=_blank
                                                         class="href_image"><img src="images/help.gif"></a></td>
                    </tr>
                {/foreach}
            {/foreach}
        </table>
    {else}
        <div class="good_mess">
            {$lang.no_system_errors}
        </div>
    {/if}
    <br>
    <form action="edit_check.php" method="post">
        <input class="btn btn-default btn-sm" type=submit name="full_check" value='{$lang.full_system_check}' id="full_check_button"><br/>
        <input type=hidden name=csrf value="{$csrf}">
    </form>
    {if $config.perfomance_check}
        <div id="analysis_status" style="margin-top: 5px">
            <button class="btn btn-default btn-sm" onclick="return jconfirm('{$lang.single_mode_confirm}', function () { exec_step(1) });">{$lang.Perfomance_analysis}</button>
        </div>
        <div id="analysis_process"
             style="width: 200px; text-align: left; border: 1px solid black; visibility: hidden; margin: 3px 0px">
            <div id="analysis_bar" style="height: 18px; width: 0px; background: #35B51A"></div>
            <div id="analysis_progress"
                 style="position: absolute; margin-top: -17px; text-align: center; width: 200px"></div>
        </div>
        <div id="analysis_report"></div>
    {/if}
    <br/>
    <a href="edit_add.php">{$lang.return_to_add_settings}</a><br><br>
</div>