Skip to content

Instantly share code, notes, and snippets.

@sergant210 sergant210/showErrors.php
Last active Aug 29, 2015

Embed
What would you like to do?
Show errors from the system error log in a new window
<?php
switch ($modx->event->name) {
case 'OnManagerPageBeforeRender':
// Определяем названия // Define titles on your language
$lang['no'] = 'Нет'; //No
$lang['yes'] = 'Есть'; //Yes
$lang['errors'] = 'Ошибки'; //Errors
$lang['errors_title'] = 'Открыть журнал ошибок в новом окне'; //Open the error log in a new window
//
$response = $modx->runProcessor('system/errorlog/get');
$resObj = $response->getObject();
$fsize = @filesize($resObj['name']);
$resObj['size'] = round($fsize / 1000 / 1000,2).' MB';
if ($fsize > 1) {
$_txt = '<span>'.$lang['yes'].'</span>';
$resObj['empty'] = false;
} else {
$_txt = $lang['no'];
$resObj['empty'] = true;
}
$_html = "<style type=\"text/css\">
.errorlog-li a {padding: 0 !important;margin-right: 7px !important;}
.errorlog-li a span {color: red; background-color: white;padding: 5px;}
#errorlog-box {background-color: #FFF;border: 2px solid #DDD;box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);position: absolute;width: 1200px;z-index: 5000;}
#errorlog-box-title {background-color: #EFEFEF;padding: 10px 5px;margin: 3px;}
#errorlog-box-body {height: 500px;padding: 10px 8px;overflow: auto;}
#errorlog-box-title button {position: absolute;top: 5px;padding: 3px 6px !important;}
#clearlog-btn {right: 35px;}
#close-btn {right: 8px;}
</style>\n";
$_html .= '<script>
function showLog(){
var w = new Ext.Window({
id: "errorlog-window",
height: 400,
width: 1200,
title: _("error_log"),
buttonAlign: "right",
items: [{
xtype: "textarea",
name: "log",
hideLabel: true,
id: "window-error-log-content",
value: config.log,
readOnly: true,
height: "97%",
width: "99%",
hidden: config.tooLarge ? true : false
},{
html: "<p>"+_("error_log_too_large",{name: config.name})+"</p>",
id: "too-large-text",
border: false,
hidden: config.tooLarge ? false : true
},{
xtype: "button",
text: _("error_log_download",{size: config.size}),
cls: "primary-button",
id: "error-log-download-btn",
style: "margin-top: 15px;",
hidden: config.tooLarge ? false : true,
handler: function () {location.href = MODx.config.connectors_url+"?action=system/errorlog/download&HTTP_MODAUTH="+MODx.siteId;},
scope: this
}],
buttons: [{
text: _("error_log"),
handler: function () { location.href = "?a=system/event" },
scope: this
}, {
text: _("clear"),
id: "error-log-clear-btn",
disabled: config.empty ? true : false,
handler: function () {
MODx.Ajax.request({
url: MODx.config.connectors_url
,params: {
action: "system/errorlog/clear"
}
,listeners: {
"success": {fn:function(r) {
var log = Ext.getCmp("window-error-log-content");
log.setValue(" ");
config.log = " ";
Ext.getCmp("error-log-clear-btn").disable();
if (config.tooLarge) {
log.show();
Ext.getCmp("too-large-text").hide();
Ext.getCmp("error-log-download-btn").hide();
config.tooLarge = false;
}
document.getElementById("errorlog-result").innerHTML = lang.no;
}}
}
});
}, scope: this
},{
text: _("close"),
handler: function () { w.close(); },
scope: this
}]
}).show();
}
var config = '.$modx->toJSON($resObj).',
lang = '.$modx->toJSON($lang).';
Ext.onReady(function() {
var usermenuUl = document.getElementById("modx-user-menu"),
firstLi = usermenuUl.firstChild,
errorlogLi = document.createElement("LI");
errorlogLi.innerHTML = "<a href=\"javascript:void(0)\" onclick=\"return false;\">"+lang.errors+":</a><a id=\"errorlog-result\" href=\"javascript:showLog()\" title=\""+lang.errors_title+"\">'.$_txt.'</a>";
errorlogLi.className = "errorlog-li";
usermenuUl.insertBefore(errorlogLi, firstLi);
});
</script>';
$modx->controller->addHtml($_html);
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.