Error: Logging database table does not exist! Try clicking "Create log DB"
';
exit();
}
$table_width_html = "";
adlog_results_table();
function adlog_results_table(){
global $wpdb;
$adlog_table = adlog_table_name();
$count = $wpdb->get_var("SELECT COUNT(*) FROM $adlog_table");
$offset = adlog_get_param('offset', 6);
$query = adlog_get_param('query', 50);
$subquery = adlog_get_param('subquery', 50);
$filter = adlog_get_param('filter', 350); //256 but allow extra space for base 64
$filter = substr(base64_decode($filter), 0, 256);
adlog_debug_log("QUERY_STRING: ".$_SERVER['QUERY_STRING']);
$ops = adlog_options();
$rows_per_page = $ops['ui_num_rows_per_page'];
if ($count > 1){
$num_pages = ceil($count / $rows_per_page);
} else {
$num_pages = 1;
}
$page = 0;
if (isset($offset)){
$page = $offset;
if ($page < 0) $page = 0;
if ($page >= $num_pages) $page = $num_pages-1;
}
$offset = $rows_per_page * $page;
if (adlog_ticked('debug_mode')) $debugquery = ", Debug";
if (adlog_ticked('ui_show_size')) $sizequery = ", Size";
if (adlog_ticked('ui_show_unit')) $unitquery = ", Unit";
if (adlog_ticked('ui_show_referrer')) $referrerquery = ", Referrer";
if (adlog_ticked('ui_show_ip')) $ipquery = ", IP";
if (adlog_ticked('ui_show_browser')) $browserquery = ", Browser";
if (adlog_ticked('ui_show_src')) $sourcequery = ", Src";
global $table_width_html;
$table_width_html = "";
$sql = "";
if ($query == 'IPCount'){
$sql = "SELECT COUNT(*) AS Clicks, IP FROM " . $adlog_table . " GROUP BY IP ORDER BY Clicks DESC LIMIT $rows_per_page OFFSET $offset";
} else if ($query == 'PageCount'){
$sql = "SELECT COUNT(*) AS Clicks, Page FROM " . $adlog_table . " GROUP BY Page ORDER BY Clicks DESC LIMIT $rows_per_page OFFSET $offset";
} else if ($query == 'ReferrerCount'){
$sql = "SELECT COUNT(*) AS Clicks, Referrer FROM " . $adlog_table . " GROUP BY Referrer ORDER BY Clicks DESC LIMIT $rows_per_page OFFSET $offset";
} else if ($query == 'BrowserCount'){
$sql = "SELECT COUNT(*) AS Clicks, Browser FROM " . $adlog_table . " GROUP BY Browser ORDER BY Clicks DESC LIMIT $rows_per_page OFFSET $offset";
} else if ($query == 'TypeCount'){
$sql = "SELECT COUNT(*) AS Clicks, Type FROM " . $adlog_table . " GROUP BY Type ORDER BY Clicks DESC LIMIT $rows_per_page OFFSET $offset";
} else {
$table_width_html = " width='100%'";
$where = "";
if (strlen($subquery) > 0){
$where = "WHERE $subquery='$filter'";
}
$sql = "SELECT ID, Type, Date $sizequery $unitquery, Page $referrerquery $ipquery $browserquery $sourcequery $debugquery FROM " . $adlog_table . " $where ORDER BY ID DESC LIMIT $rows_per_page OFFSET $offset";
}
?>
'; ?>
Navigation:
<< First < Previous ';
}
if ($page == $num_pages-1){
echo 'Next > Last >>';
} else {
echo 'Next > Last >>';
}
?>
| Refresh ↻
| Reports:
All logs
Type
IPs
Pages
Referrers
Browsers
All logs' to reset.
";
}
function adlog_print_table($query) {
$ops = adlog_options();
adlog_debug_log("Query: $query");
global $wpdb;
$results = $wpdb->get_results($query);
if ($results === false) die("Error with: $query
Msg: ".$wpdb->last_error);
echo '
';
global $table_width_html;
echo "";
echo '';
$column_names = array();
// Output headers
$columns = $wpdb->get_col_info('name');
foreach($columns as $column){
echo "| $column | ";
$column_names[] = $column;
}
echo '
';
if (count($results)== 0) die("
The logging table is currently empty.
If you have just installed the plugin and want to try it with some example data you can add some test data from the 'Testing the plugin' section below. Then click the 'Refresh' link above the table to see the new data.
");
// Output data
$count = 1;
foreach ($results as $row) {
if ($count % 2 == 0){
echo '';
} else {
echo "
";
}
$col_num = 0;
foreach ($row as $column) {
if ($column_names[$col_num] == 'ID'){
echo "| $column";
} else if ($column_names[$col_num] == 'Type'){
} else if ($column_names[$col_num] == 'IP'){
$ip = long2ip($column);
if ($ip == "0.0.0.0"){
echo " | 0.0.0.0 (could not retrieve IP)";
} else {
echo " | $ip";
}
} else if ($column_names[$col_num] == 'Page' || $column_names[$col_num] == 'Referrer'){
echo " | $column";
} else if ($column_names[$col_num] == 'Browser') {
echo " | $column";
} else if ($column_names[$col_num] == 'Debug'){
echo " | $column";
} else {
echo " | $column";
}
if ($column_names[$col_num] == 'Type'){
echo " | ";
}
if ($column_names[$col_num] != 'ID' && $column_names[$col_num] != 'Date' && $column_names[$col_num] != 'Clicks'){
$encoded = base64_encode($column); // because some web servers reject the request if a get parameter has a URL from another site in it
echo "";
}
if ($column_names[$col_num] != 'ID' && $column_names[$col_num] != 'Date' && $column_names[$col_num] != 'Clicks' && $column_names[$col_num] != 'Type'){
echo "⇓";
}
if ($column_names[$col_num] == 'Type'){
echo " ";
}
if ($column_names[$col_num] != 'ID' && $column_names[$col_num] != 'Date' && $column_names[$col_num] != 'Clicks'){
echo "";
}
echo " | ";
++$col_num;
}
echo "
\n";
++$count;
}
echo "\n";
}
function adlog_debug_log($string){
if (adlog_ticked('debug_mode')) echo "DEBUGMODE: $string
";
}
function adlog_get_param($param, $max_length=128) {
if(isset($_GET[$param])) {
return mysql_real_escape_string(substr($_GET[$param],0,$max_length));
}
return "";
}
?>