<?php
/**
 * LoadErrorlog.php
 */
    $sAppPath = dirname(dirname(__DIR__));
    if (is_readable($sAppPath.'/config.php')) {require ($sAppPath.'/config.php');}
    if (!class_exists('admin', false)) {require (WB_PATH.'/framework/class.admin.php');}
    // An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.
    $aRequestVars = $_REQUEST;
    $sErrorlogFile = WB_PATH.'/var/logs/php_error.log.php';
    $sErrorlogUrl  = WB_URL .'/var/logs/php_error.log.php';
    $aJsonRespond['url'] = $sErrorlogUrl;
    // initialize json_respond array  (will be sent back)
    $aJsonRespond = array();
    $aJsonRespond['content'] = array();
    $aJsonRespond['message'] = 'Load operation failed';
    $aJsonRespond['success'] = false;
    $admin = new admin('##skip##', false, false);
    if ( (int)$admin->get_user_id() != 1){
        $aJsonRespond['message'] = 'illegal file access';
        exit(json_encode($aJsonRespond));
    }
    if (!($aJsonRespond['content'] = file($sErrorlogFile, FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES|FILE_TEXT))){
        exit(json_encode($aJsonRespond));
    }
    $output = implode('<br />',$aJsonRespond['content']);

    // If the script is still running, set success to true
    $aJsonRespond['success'] = 'true';
// and echo the answer as json to the ajax function
    $output = json_encode ($output, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
    echo stripslashes($output);

