saimod log pagination, filter & search

This commit is contained in:
Ulf Gebhardt 2015-06-11 00:53:55 +02:00
parent 7563357a13
commit 4f4aeefa97
13 changed files with 75 additions and 47 deletions

View File

@ -24,7 +24,7 @@ INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`,
INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`, `type`, `div`, `url`, `func`, `php_class`) VALUES (61, 42, 'list', 'files', 60, 0, 0, '#tab_files', './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_files&action=tab&name=${folder}', 'init_saimod_sys_files_list', '\\SYSTEM\\SAI\\saimod_sys_files');
INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`, `type`, `div`, `url`, `func`, `php_class`) VALUES (70, 42, 'log', 'log', -1, 0, 0, '#content', './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log', 'init_saimod_sys_log', '\\SYSTEM\\SAI\\saimod_sys_log');
INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`, `type`, `div`, `url`, `func`, `php_class`) VALUES (71, 42, 'list', 'log', 70, 0, 0, '#tab_log', './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log&action=filter&filter=${filter}', 'init_saimod_sys_log_log', '\\SYSTEM\\SAI\\saimod_sys_log');
INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`, `type`, `div`, `url`, `func`, `php_class`) VALUES (71, 42, 'list', 'log', 70, 0, 0, '#tab_log', './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log&action=filter&filter=${filter}&search=${search}&page=${page}', 'init_saimod_sys_log_log', '\\SYSTEM\\SAI\\saimod_sys_log');
INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`, `type`, `div`, `url`, `func`, `php_class`) VALUES (72, 42, 'stats', 'log', 70, 0, 1, '#tab_log', './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log&action=stats', 'init_saimod_sys_log_stats', '\\SYSTEM\\SAI\\saimod_sys_log');
INSERT INTO `system_page` (`id`, `group`, `name`, `state`, `parent_id`, `login`, `type`, `div`, `url`, `func`, `php_class`) VALUES (73, 42, 'error', 'log', 70, 0, 1, '#tab_log', './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log&action=error&error=${error}', '', '');

View File

@ -47,6 +47,8 @@ INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `nam
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (200, 42, 0, 0, '_SYSTEM_SAI_saimod_sys_log', 'action', NULL);
--
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (201, 42, 3, 200, 'filter', 'filter', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (202, 42, 3, 200, 'filter', 'search', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (203, 42, 3, 200, 'filter', 'page', 'UINT0');
--
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (210, 42, 3, 200, 'error', 'error', 'INT');
--

View File

@ -267,6 +267,7 @@
INSERT INTO `system_text` (`id`, `lang`, `text`, `author`, `author_edit`, `time_create`, `time_edit`) VALUES ('basic_placeholder_search', 'enUS', 'I\'m searching for...', 0, 0, '2015-04-15 18:29:16', '0000-00-00 00:00:00');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_placeholder_search', 'basic');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_placeholder_search', 'sai_todo');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_placeholder_search', 'sai_log');
DELETE FROM `system_text` WHERE id = 'basic_progress';
DELETE FROM `system_text_tag` WHERE id = 'basic_progress';
@ -302,6 +303,7 @@
INSERT INTO `system_text` (`id`, `lang`, `text`, `author`, `author_edit`, `time_create`, `time_edit`) VALUES ('basic_rows', 'frFR', 'lignes', 3, 3, '2015-04-20 16:33:19', '2015-04-20 16:33:19');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_rows', 'basic');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_rows', 'sai_log');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_rows', 'sai_todo');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_rows', 'sai_security');
DELETE FROM `system_text` WHERE id = 'basic_save';
@ -463,6 +465,7 @@
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_search', 'basic');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_search', 'sai_security');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_search', 'sai_todo');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_search', 'sai_log');
DELETE FROM `system_text` WHERE id = 'basic_send_email';
DELETE FROM `system_text_tag` WHERE id = 'basic_send_email';
@ -591,6 +594,14 @@
INSERT INTO `system_text` (`id`, `lang`, `text`, `author`, `author_edit`, `time_create`, `time_edit`) VALUES ('basic_priority', 'enUS', 'Priority', 2, 1, '2015-04-16 23:11:18', '2015-04-16 23:11:18');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_priority', 'basic');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_priority', 'sai_todo');
DELETE FROM `system_text` WHERE id = 'basic_page';
DELETE FROM `system_text_tag` WHERE id = 'basic_page';
INSERT INTO `system_text` (`id`, `lang`, `text`, `author`, `author_edit`, `time_create`, `time_edit`) VALUES ('basic_page', 'deDE', 'Seite', 1, 1, '2015-04-16 23:11:18', '2015-04-16 16:48:36');
INSERT INTO `system_text` (`id`, `lang`, `text`, `author`, `author_edit`, `time_create`, `time_edit`) VALUES ('basic_page', 'enUS', 'Page', 2, 1, '2015-04-16 23:11:18', '2015-04-16 23:11:18');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_page', 'basic');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_page', 'sai_todo');
INSERT INTO `system_text_tag` (`id`, `tag`) VALUES ('basic_page', 'sai_log');
-- SAI
DELETE FROM `system_text` WHERE id = 'sai_api_title';

View File

@ -8,11 +8,18 @@ function init_saimod_sys_log() {
});
};
function register_search(){
$('#btn_search').click(function(){
system.load($(this).attr('state')+$('#input_search').val(),true);
});
}
function init_saimod_sys_log_log() {
$("#sai_mod_log_table").tablesorter();
$('#tabs_log li').each(function(){
$(this).removeClass('active');});
$('#menu_loglist').parent().addClass('active');
register_search();
}
function init_saimod_sys_log_stats() {

View File

@ -10,12 +10,13 @@ class SYS_SAIMOD_LOG_FILTER extends \SYSTEM\DB\QP {
' ON '.\SYSTEM\DBD\system_log::NAME_PG.'.'.\SYSTEM\DBD\system_log::FIELD_USER.
' = '.\SYSTEM\DBD\system_user::NAME_PG.'.'.\SYSTEM\DBD\system_user::FIELD_ID.
' WHERE '.\SYSTEM\DBD\system_log::FIELD_CLASS.' LIKE $1'.
' ORDER BY '.\SYSTEM\DBD\system_log::FIELD_TIME.' DESC, '.\SYSTEM\DBD\system_log::NAME_PG.'."'.\SYSTEM\DBD\system_log::FIELD_ID.'" DESC LIMIT 100;',
' ORDER BY '.\SYSTEM\DBD\system_log::FIELD_TIME.' DESC, '.\SYSTEM\DBD\system_log::NAME_PG.'."'.\SYSTEM\DBD\system_log::FIELD_ID.'" DESC;',
//mys
'SELECT * FROM '.\SYSTEM\DBD\system_log::NAME_MYS.
' LEFT JOIN '.\SYSTEM\DBD\system_user::NAME_MYS.
' ON '.\SYSTEM\DBD\system_log::NAME_MYS.'.'.\SYSTEM\DBD\system_log::FIELD_USER.
' = '.\SYSTEM\DBD\system_user::NAME_MYS.'.'.\SYSTEM\DBD\system_user::FIELD_ID.
' WHERE '.\SYSTEM\DBD\system_log::FIELD_CLASS.' LIKE ?'.
' ORDER BY '.\SYSTEM\DBD\system_log::FIELD_TIME.' DESC, '.\SYSTEM\DBD\system_log::NAME_MYS.'.'.\SYSTEM\DBD\system_log::FIELD_ID.' DESC LIMIT 100;'
' AND ('.\SYSTEM\DBD\system_log::FIELD_MESSAGE.' LIKE ? OR '.\SYSTEM\DBD\system_log::FIELD_FILE.' LIKE ? OR '.\SYSTEM\DBD\system_log::FIELD_IP.' LIKE ?)'.
' ORDER BY '.\SYSTEM\DBD\system_log::FIELD_TIME.' DESC, '.\SYSTEM\DBD\system_log::NAME_MYS.'.'.\SYSTEM\DBD\system_log::FIELD_ID.' DESC;'
);}}

View File

@ -11,7 +11,7 @@ class SYS_SAIMOD_LOG_FILTER_COUNT extends \SYSTEM\DB\QP {
//mys
'SELECT COUNT(*) as count'.
' FROM '.\SYSTEM\DBD\system_log::NAME_MYS.
' WHERE '.\SYSTEM\DBD\system_log::FIELD_CLASS.
' LIKE ?;'
' WHERE '.\SYSTEM\DBD\system_log::FIELD_CLASS.' LIKE ?'.
' AND ('.\SYSTEM\DBD\system_log::FIELD_MESSAGE.' LIKE ? OR '.\SYSTEM\DBD\system_log::FIELD_FILE.' LIKE ? OR '.\SYSTEM\DBD\system_log::FIELD_IP.' LIKE ?);'
);}}

View File

@ -292,37 +292,41 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
$vars = array_merge($vars,\SYSTEM\PAGE\text::tag(\SYSTEM\DBD\system_text::TAG_SAI_LOG));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_error.tpl'), $vars);}
public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_filter($filter = "%"){
$filter_ = $filter;
public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_filter($filter = "%",$search="%",$page=0){
$filter = str_replace('\\', '\\\\', $filter);
$count = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTER_COUNT::Q1(array($filter));
$res = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTER::QQ(array($filter));
$table='';
while($r = $res->next()){
//print_r($r);
$count = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTER_COUNT::Q1(array($filter,$search,$search,$search))['count'];
$vars = array();
$vars['filter'] = $filter;
$vars['search'] = $search;
$vars['page'] = $page;
$res = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTER::QQ(array($filter,$search,$search,$search));
$vars['table'] = '';
$count_filtered = 0;
$res->seek(100*$page);
while(($r = $res->next()) && ($count_filtered < 100)){
$r['class_row'] = self::tablerow_class($r['class']);
$r['time'] = \SYSTEM\time::time_ago_string(strtotime($r['time']));
$r['message'] = htmlspecialchars(substr($r['message'],0,255));
$r['request_uri'] = htmlspecialchars($r['request_uri']);
$table .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_table_row.tpl'),$r);
$vars['table'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_table_row.tpl'),$r);
$count_filtered++;
}
$vars = array();
$vars['count'] = $count['count'];
$vars['error_filter'] = self::generate_error_filters($filter_);
$vars['pagination'] = '';
for($i=0;$i < ceil($count/100);$i++){
$data = array('page' => $i,'search' => $search, 'filter' => $filter, 'active' => ($i == $page) ? 'active' : '');
$vars['pagination'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_pagination.tpl'), $data);
}
$vars['count'] = $count_filtered.'/'.$count;
$vars['error_filter'] = '';
$res = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTERS::QQ();
while($row = $res->next()){
$data = array('active' => ($filter == $row['class'] ? 'active' : ''), 'filter' => $row['class'], 'search' => $search);
$vars['error_filter'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_error_filter.tpl'),$data);}
$vars['active'] = ($filter == '%' ? 'active' : '');
$vars['table'] = $table;
$vars = array_merge($vars, \SYSTEM\PAGE\text::tag(\SYSTEM\DBD\system_text::TAG_SAI_LOG));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_filter.tpl'),$vars);
}
private static function generate_error_filters($filter){
$res = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTERS::QQ();
$result = '';
while($row = $res->next()){
$result .= '<li'.($filter == $row['class'] ? ' class="active"' : '').'><a href="#!log;filter.'.$row['class'].'">'.$row['class'].'</a></li>';}
return $result;
}
public static function sai_mod__SYSTEM_SAI_saimod_sys_log(){
$vars = \SYSTEM\PAGE\text::tag(\SYSTEM\DBD\system_text::TAG_SAI_LOG);
$vars['PICPATH'] = \SYSTEM\WEBPATH(new \SYSTEM\PSAI(), 'modules/saimod_sys_log/img/');

View File

@ -0,0 +1 @@
<li class="${active}"><a href="#!log;filter.${filter};search.${search}">${filter}</a></li>

View File

@ -1,25 +1,26 @@
<ul class="nav nav-pills" id="error_filter">
<li class="${active}"><a href="#!log" filter="%">${basic_all}</a></li>
<li class="${active}"><a href="#!log;filter.%;search.${search}">${basic_all}</a></li>
${error_filter}
<button class="btn-sm btn btn-success" state="log;filter.${filter};search." id="btn_search" type="submit" style="float: right; margin-left: 10px;"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> ${basic_search}</button>
<input class="input-medium search-query action-control" id="input_search" type="text" placeholder="${basic_placeholder_search}" size="20" style="float: right;" value="${search}"/>
</ul>
<div id="table_log">
${basic_rows}: ${count}
<h6>${basic_rows}: ${count} ${basic_page}: ${page}</h6>
<table class="table table-hover table-condensed tablesorter" id="sai_mod_log_table">
<thead>
<tr>
<th>${time_ago}</th>
<th>${table_class}</th>
<th>${table_message}</th>
<th>${table_file}</th>
<th>${table_line}</th>
<th>${table_ip}</th>
<th>${table_url}</th>
<th>${table_user}</th>
<th>${table_querytime}</th>
</tr>
</thead>
<tbody>
${table}
</tbody>
<tr>
<th>${time_ago}</th>
<th>${table_class}</th>
<th>${table_message}</th>
<th>${table_file}</th>
<th>${table_line}</th>
<th>${table_ip}</th>
<th>${table_url}</th>
<th>${table_user}</th>
<th>${table_querytime}</th>
</tr>
${table}
</table>
<ul class="pagination">
${pagination}
</ul>
</div>

View File

@ -0,0 +1 @@
<li class="${active}"><a href="#!log;filter.${filter};search.${search};page.${page}">${page}</a></li>

View File

@ -22,7 +22,7 @@ function init_saimod_sys_todo() {
function register_search(){
$('#btn_search').click(function(){
system.load($(this).attr('state')+$('#input_search').val()+$(this).attr('state2'),true);
system.load($(this).attr('state')+$('#input_search').val(),true);
});
}

View File

@ -7,10 +7,10 @@
<li class="${filter_gen}"><a href="#!${state};filter.gen;search.${search}">${basic_generated}</a></li>
<li class="${filter_user}"><a href="#!${state};filter.user;search.${search}">${basic_user}</a></li>
<li class="${filter_report}"><a href="#!${state};filter.report;search.${search}">${basic_report}</a></li>
<button class="btn-sm btn btn-success" state="${state};filter.${filter};search." state2=";page.${page}" id="btn_search" type="submit" style="float: right; margin-left: 10px;"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> ${basic_search}</button>
<button class="btn-sm btn btn-success" state="${state};filter.${filter};search." id="btn_search" type="submit" style="float: right; margin-left: 10px;"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> ${basic_search}</button>
<input class="input-medium search-query action-control" id="input_search" type="text" placeholder="${basic_placeholder_search}" size="20" style="float: right;" value="${search}"/>
</ul>
<h6>Rows: ${count} Page: ${page}</h6>
<h6>${basic_rows}: ${count} ${basic_page}: ${page}</h6>
<table class="table table-hover table-condensed">
<tr>
<th>${time_ago}</th>

View File

@ -1 +1 @@
<li><a class="${active}" href="#!${state};filter.all;search.${search};page.${page}">${page}</a></li>
<li class="${active}"><a href="#!${state};filter.all;search.${search};page.${page}">${page}</a></li>