add simple search to log view

This commit is contained in:
Felix Favre 2014-12-15 21:23:57 +01:00
parent 388dd0e136
commit be1bb5fbeb
2 changed files with 24 additions and 5 deletions

View File

@ -18,4 +18,11 @@ function LogEntries() {
return sql_select("SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000"); return sql_select("SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000");
} }
/**
* Returns log entries filtered by a keyword
*/
function LogEntries_filter($keyword) {
return sql_select("SELECT * FROM `LogEntries` WHERE `nick` LIKE '%" . sql_escape($keyword) . "%' OR `message` LIKE '%" . sql_escape($keyword) . "%' ORDER BY `timestamp` DESC");
}
?> ?>

View File

@ -4,7 +4,15 @@ function admin_log_title() {
} }
function admin_log() { function admin_log() {
if (isset($_POST['keyword'])) {
$filter = $_POST['keyword'];
$log_entries_source = LogEntries_filter($_POST['keyword']);
} else {
$filter = "";
$log_entries_source = LogEntries(); $log_entries_source = LogEntries();
}
$log_entries = array(); $log_entries = array();
foreach ($log_entries_source as $log_entry) { foreach ($log_entries_source as $log_entry) {
$log_entry['date'] = date("d.m.Y H:i", $log_entry['timestamp']); $log_entry['date'] = date("d.m.Y H:i", $log_entry['timestamp']);
@ -13,6 +21,10 @@ function admin_log() {
return page_with_title(admin_log_title(), array( return page_with_title(admin_log_title(), array(
msg(), msg(),
form(array(
form_text('keyword', _("Suche"), $filter),
form_submit(_("Suche"), "Go")
)),
table(array( table(array(
'date' => "Time", 'date' => "Time",
'nick' => "Angel", 'nick' => "Angel",