", $text);
// Rolling log options
//====================
$text = "
\n
";
$ns->tablerender("
".RL_LAN_011."
", $text);
}
//====================================================================
// LOG VIEW MENU
//====================================================================
if (isset($page_title[$action]))
{
$from = intval(varset($qs[1], 0)); // First entry to display
$amount = max(varset($pref['sys_log_perpage'], 20),5); // Number of entries per page
// Array decides which filters are active for each log. There are 4 columns total. All but 'datetimes' occupy 2. Must specify multiple of 4 columns - add 'blank' if necessary
$active_filters = array('adminlog' => array('datetimes'=>0,'ipfilter'=>0,'userfilter'=>0,'eventfilter'=>0,'priority'=>0),
'auditlog' => array('datetimes'=>0,'ipfilter'=>0,'userfilter'=>0,'eventfilter'=>0,'blank'=>2),
'rolllog' => array('datetimes'=>0,'ipfilter'=>0,'userfilter'=>0,'eventfilter'=>0,'priority'=>0,'callerfilter'=>0,'blank'=>2),
'downlog' => array('datetimes'=>0,'ipfilter'=>0,'userfilter'=>0,'downloadidfilter'=>0,'blank'=>2),
'detailed' => array('datestart'=>0, 'ipfilter'=>0,'userfilter'=>0,'eventfilter'=>0,'blank'=>2),
'comments' => array('datetimes'=>1, 'ipfilter'=>0,'userfilter'=>0,'eventfilter'=>0,'blank'=>2)
);
// Arrays determine column widths, headings, displayed fields for each log
$col_fields = array('adminlog' => array('cf_datestring','dblog_type','dblog_ip','dblog_user_id','user_name','dblog_eventcode','dblog_title','dblog_remarks'),
'auditlog' => array('cf_datestring','dblog_ip','dblog_user_id','dblog_user_name','dblog_eventcode','dblog_title','dblog_remarks'),
'rolllog' => array('cf_datestring','dblog_type','dblog_ip','dblog_user_id','dblog_user_name','dblog_eventcode','dblog_caller','dblog_title','dblog_remarks'),
'downlog' => array('cf_datestring','dblog_ip','dblog_user_id','user_name','download_request_download_id','download_name'),
'detailed' => array('cf_microtime','cf_microtimediff','source','dblog_type','dblog_ip','dblog_user_id','user_name','dblog_eventcode','dblog_title','dblog_remarks'),
'comments' => array('cf_datestring', 'comment_id', 'comment_pid', 'comment_item_id', 'comment_subject', 'comment_author_id', 'comment_author_name', 'comment_ip', 'comment_type', 'comment_comment', 'comment_blocked', 'comment_lock', 'del_check')
);
$col_widths = array('adminlog' => array(18,4,14,7,15,8,14,20), // Date - Pri - IP - UID - User - Code - Event - Info
'auditlog' => array(18,14,7,15,8,14,24),
'rolllog' => array(15,4,12,6,12,7,13,13,18), // Date - Pri - IP - UID - User - Code - Caller - Event - Info
'downlog' => array(18,14,7,15,8,38),
'detailed' => array(10,8,6,4,14,6,17,7,17,21),
'comments' => array(14,7,7,7,14,3,10,12,5,17,1,1,1)
);
$col_titles = array('adminlog' => array(RL_LAN_019,RL_LAN_032,RL_LAN_020,RL_LAN_104,RL_LAN_022,RL_LAN_023,RL_LAN_025,RL_LAN_033),
'auditlog' => array(RL_LAN_019,RL_LAN_020,RL_LAN_104,RL_LAN_022,RL_LAN_023,RL_LAN_025,RL_LAN_033),
'rolllog' => array(RL_LAN_019,RL_LAN_032,RL_LAN_020,RL_LAN_104,RL_LAN_022,RL_LAN_023,RL_LAN_024,RL_LAN_025,RL_LAN_033),
'downlog' => array(RL_LAN_019,RL_LAN_020,RL_LAN_104,RL_LAN_022,RL_LAN_068,RL_LAN_069),
'detailed' => array(RL_LAN_097,RL_LAN_096,RL_LAN_098,RL_LAN_032,RL_LAN_020,RL_LAN_104,RL_LAN_022,RL_LAN_023,RL_LAN_025,RL_LAN_033),
'comments' => array(RL_LAN_019, RL_LAN_100, RL_LAN_101, RL_LAN_102, RL_LAN_103, RL_LAN_104, RL_LAN_105, RL_LAN_020, RL_LAN_106, RL_LAN_107, RL_LAN_108, RL_LAN_109, RL_LAN_110)
);
// For DB where the delete option is available, specifies the ID field
$delete_field = array(
'comments' => 'comment_id'
);
// Only need to define entries in this array if the base DB query is non-standard (i.e. different field names and/or joins)
$base_query = array(
'downlog' => "SELECT SQL_CALC_FOUND_ROWS
dbl.download_request_id as dblog_id,
dbl.download_request_userid as dblog_user_id,
dbl.download_request_ip as dblog_ip,
dbl.download_request_download_id,
dbl.download_request_datestamp as dblog_datestamp,
d.download_name,
u.user_name
FROM #download_requests AS dbl
LEFT JOIN #user AS u ON dbl.download_request_userid=u.user_id
LEFT JOIN #download AS d ON dbl.download_request_download_id=d.download_id
",
'detailed' => "SELECT SQL_CALC_FOUND_ROWS cl.*, u.* FROM (
SELECT dblog_datestamp + (dblog_microtime/1000000) AS dblog_time, dblog_user_id, dblog_eventcode, dblog_title, dblog_remarks, dblog_type, dblog_ip, 'roll' AS source FROM `#dblog`
UNION
SELECT dblog_datestamp + (dblog_microtime/1000000) AS dblog_time, dblog_user_id, dblog_eventcode, dblog_title, dblog_remarks, '-' AS dblog_type, dblog_ip, 'audit' AS source FROM `#audit_log`
UNION
SELECT dblog_datestamp + (dblog_microtime/1000000) AS dblog_time, dblog_user_id, dblog_eventcode, dblog_title, dblog_remarks, dblog_type, dblog_ip, 'admin' AS source FROM `#admin_log`) AS cl
LEFT JOIN `#user` AS u ON cl.dblog_user_id=u.user_id ",
'comments' => "SELECT SQL_CALC_FOUND_ROWS *, comment_datestamp AS dblog_datestamp FROM `#comments` AS c"
);
// The filters have to use the 'actual' db field names. So the following table sets the defaults and the exceptions which vary across the range of tables supported
$map_filters = array(
'default' => array('datetimes' => '`dblog_datestamp`', 'ipfilter' => '`dblog_ip`', 'userfilter' => '`dblog_user_id`', 'eventfilter' => '`dblog_eventcode`'),
'downlog' => array('datetimes' => '`download_request_datestamp`', 'ipfilter' => '`download_request_ip`', 'userfilter' => '`download_request_userid`'),
'detailed' => array('datestart' => '`dblog_time`'),
'comments' => array('datetimes' => '`comment_datestamp`', 'ipfilter' => '`comment_ip`', 'eventfilter' => 'comment_type', 'userfilter' => '`comment_author_id`')
);
// Check things
if ($start_time >= $end_time)
{ // Make end time beginning of tomorrow
$tempdate = getdate();
$end_time = mktime(0,0,0,$tempdate['mon'],$tempdate['mday']+1,$tempdate['year']); // Seems odd, but mktime will work this out OK
// (or so the manual says)
}
// Now work out the query - only use those filters which are displayed
$qry = '';
$and_array = array();
foreach ($active_filters[$action] as $fname=>$fpars)
{
$filter_field = varset($map_filters[$action][$fname],$map_filters['default'][$fname]);
switch ($fname)
{
case 'datetimes' :
if ($start_enabled && ($start_time > 0)) $and_array[] = "{$filter_field} >= ".intval($start_time);
if ($end_enabled && ($end_time > 0)) $and_array[] = "{$filter_field} <= ".intval($end_time);
switch ($fpars)
{
case 1 :
$sort_field = 'comment_datestamp';
break;
default :
// $sort_field = 'dblog_time'; // Non-default sort field
}
break;
case 'datestart' :
$sort_field = 'dblog_time'; // Non-default sort field
if ($start_time == 0)
{
$end_time = time();
$start_time = $end_time - 300; // Default to last 5 mins
}
$and_array[] = "{$filter_field} >= ".intval($start_time);
$and_array[] = "{$filter_field} <= ".intval($end_time);
break;
case 'ipfilter' :
if ($ipaddress_filter != "")
{
if (substr($ipaddress_filter,-1) == '*')
{ // Wildcard to handle - mySQL uses %
$and_array[] = "{$filter_field} LIKE '".substr($ipaddress_filter,0,-1)."%' ";
}
else
{
$and_array[] = "{$filter_field}= '".$ipaddress_filter."' ";
}
}
break;
case 'userfilter' :
if ($user_filter != '') $and_array[] = "{$filter_field} = ".intval($user_filter);
break;
case 'eventfilter' :
if ($event_filter != '')
{
if (substr($event_filter,-1) == '*')
{ // Wildcard to handle - mySQL uses %
$and_array[] = " {$filter_field} LIKE '".substr($event_filter,0,-1)."%' ";
}
else
{
$and_array[] = "{$filter_field}= '".$event_filter."' ";
}
}
break;
case 'callerfilter' :
if ($caller_filter != '')
{
if (substr($caller_filter,-1) == '*')
{ // Wildcard to handle - mySQL uses %
$and_array[] = "dblog_caller LIKE '".substr($caller_filter,0,-1)."%' ";
}
else
{
$and_array[] = "dblog_caller= '".$caller_filter."' ";
}
}
break;
case 'priority' :
if (($pri_filter_val != "") && ($pri_filter_cond != "") && ($pri_filter_cond != "xx"))
{
switch ($pri_filter_cond)
{
case "lt" :
$and_array[] = "dblog_type <= '{$pri_filter_val}' ";
break;
case "eq" :
$and_array[] = "dblog_type = '{$pri_filter_val}' ";
break;
case "gt" :
$and_array[] = "dblog_type >= '{$pri_filter_val}' ";
break;
}
}
break;
case 'downloadidfilter' :
if ($downloadid_filter != '') $and_array[] = "download_request_download_id = ".intval($downloadid_filter);
break;
}
}
if (count($and_array)) $qry = " WHERE ".implode(' AND ',$and_array);
$limit_clause = " LIMIT {$from}, {$amount} ";
if (isset($base_query[$action]))
{
$qry = $base_query[$action].$qry." ORDER BY {$sort_field} ".$sort_order;
}
else
{
$qry = "SELECT SQL_CALC_FOUND_ROWS dbl.*,u.user_name FROM #".$log_db_table[$action]." AS dbl LEFT JOIN #user AS u ON dbl.dblog_user_id=u.user_id".$qry." ORDER BY {$sort_field} ".$sort_order;
}
$num_entry = 0;
if ($sql->db_Select_gen($qry.$limit_clause))
{
$num_entry = $sql->total_results;
}
if ($from > $num_entry)
{
$from = 0; // We may be on a later page
$limit_clause = " LIMIT {$from}, {$amount} ";
$sql->db_Select_gen($qry.$limit_clause); // Re-run query with new value of $from
$num_entry = $sql->total_results;
}
// Start by putting up the filter boxes
$text = "
";
// Next bit is the actual log display - the arrays define column widths, titles, fields etc for each log
$column_count = count($col_widths[$action]);
$text .= "