<?php

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

File:         display_log.php
Description:  Administrative module to display log

*/

    include "../modules/mod_admin.php";

    $errorString = "";

    // Check privileges
    check_login();
    if (user_is_admin() == false)
    {
        log_out();
        return;
    }

    // Cancel log?
    if (isset($_POST['log_Cancel']))
    {
        header('location: ' . $ADMIN_MAIN_SITE);
        return;
    }
    // Clean frontend log?
    if (isset($_POST['log_FrontendClean']))
    {
        $cFile = new cTextFile;
        if ($cFile->SaveToFile($FRONT_LOG_FILE, "") == true)
        {
            log_message ('User ' . get_user_name() . ' cleaned frontend log file');
            header('location: ' . $ADMIN_MAIN_SITE);
            return;
        }
        $errorString = get_translation('admin_syslog_errorsave') . ': ' . $FRONT_LOG_FILE . '!';
    }
    // Clean bakcend log?
    if (isset($_POST['log_BackEndClean']))
    {
        $cFile = new cTextFile;
        if ($cFile->SaveToFile($ADMIN_LOG_FILE, "") == true)
        {
            log_message ('User ' . get_user_name() . ' cleaned backend log file');
            header('location: ' . $ADMIN_MAIN_SITE);
            return;
        }
        $errorString = get_translation('admin_syslog_errorsave') . ': ' . $ADMIN_LOG_FILE . '!';
    }


    // Display
    print_admin_header(get_translation('admin_syslog_head'), true, get_translation('admin_login_logout'), "", true, get_translation('admin_backtomain'));
    if ($errorString !="")
        print_error_message($errorString);

    echo_r ('<form method="post" action="">');

    // Front log
    echo_r ('<br>');
    echo_r ('<table border="0" width="100%">');
    echo_r ('  <tr>');
    echo_r ('    <td>' . get_translation('admin_syslog_page') . ': </td>');
    echo_r ('    <td><textarea cols="100" rows="15" name="log_content" wrap="off">');
    include $FRONT_LOG_FILE;
    echo_r ('    </textarea></td>');
    echo_r ('  </tr>');
    echo_r ('  <tr>');
    echo_r ('    <td>' . get_translation('admin_syslog_filesize') . ': ' . sprintf("%.2f", filesize($FRONT_LOG_FILE) / 1024) . ' KB</td>');
    echo_r ('    <td>');
    $percValue = filesize($FRONT_LOG_FILE) * (100 / $MAX_LOG_SIZE);
    echo_r ('     <table border="0" width="60%" cellspacing="0" cellpadding="0">');
    echo_r ('      <tr style="height: 10px;">');
    for ($i = 10; $i <= 100; $i += 10)
    {
        if ($percValue >= $i)
            echo_r('       <td bgcolor="blue"></td>');
        else
            echo_r('       <td bgcolor="silver"></td>');
    }
    echo_r ('      </tr>');
    echo_r ('     </table>');
    echo_r ('    </td>');
    echo_r ('  </tr>');
    echo_r ('  <tr>');
    echo_r ('    <td></td>');
    echo_r ('    <td>');
    echo_r ('     <p align="right"><input type="submit" class="bottom_btn" name="log_FrontendClean" value="' . get_translation('admin_clean') . '"></p><br>');
    echo_r ('    </td>');
    echo_r ('  </tr>');
    echo_r ('</table>');

    // Backend log
    echo_r ('<hr>');
    echo_r ('<table border="0" width="100%">');
    echo_r ('  <tr>');
    echo_r ('    <td>' . get_translation('admin_syslog_admin') . ': </td>');
    echo_r ('    <td><textarea cols="100" rows="15" name="log_content" wrap="off">');
    include $ADMIN_LOG_FILE;
    echo_r ('    </textarea></td>');
    echo_r ('  </tr>');
    echo_r ('  <tr>');
    echo_r ('    <td>' . get_translation('admin_syslog_filesize') . ': ' . sprintf("%.2f", filesize($ADMIN_LOG_FILE) / 1024) . ' KB</td>');
    echo_r ('    <td>');
    $percValue = filesize($ADMIN_LOG_FILE) * (100 / $MAX_LOG_SIZE);
    echo_r ('     <table border="0" width="60%" cellspacing="0" cellpadding="0">');
    echo_r ('      <tr style="height: 10px;">');
    for ($i = 10; $i <= 100; $i += 10)
    {
        if ($percValue >= $i)
            echo_r('       <td bgcolor="blue"></td>');
        else
            echo_r('       <td bgcolor="silver"></td>');
    }
    echo_r ('      </tr>');
    echo_r ('     </table>');
    echo_r ('    </td>');
    echo_r ('  </tr>');
    echo_r ('  <tr>');
    echo_r ('    <td></td>');
    echo_r ('    <td>');
    echo_r ('     <p align="right"><input type="submit" class="bottom_btn" name="log_BackEndClean" value="' . get_translation('admin_clean') . '"></p>');
    echo_r ('    </td>');
    echo_r ('  </tr>');
    echo_r ('</table>');
    echo_r ('</form>');

    print_bottom_links("log_Cancel", get_translation('admin_ok'));

    print_admin_footer();
?>